Ben Lynn
crypto.stanford.edu/~blynn · Personal blog · on HN since 2009
Ben Lynn, a Stanford-affiliated programmer, writes on functional programming, compilers, lambda calculus, geometric algebra and security, including a self-hosting Haskell compiler.
What HN saysCommenters praise his series on building a self-hosting Haskell compiler, his IOCCC entry, and his lambda calculus pages as helpful for learning language theory.
51HN people shared it
26linked it in comments
28stories submitted
1.6Kstory points
9 months agolast shared
2009people per year2026
Most-shared posts
- 1All Hail Geometric Algebra6 people · 290 points · first shared 2018 · 80 comments on HN
- 2Compilers for Contrarians6 people · 74 points · first shared 2020 · 2 comments on HN
- 3APL and J (2015)5 people · 85 points · first shared 2019 · 38 comments on HN
- 4Lambda5 people · first shared 2021
- 564-Bit Linux Return-Oriented Programming4 people · 218 points · first shared 2015 · 18 comments on HN
- 6Lisp4 people · first shared 2017
- 7Haskell Sorcery3 people · 9 points · first shared 2015 · discussion on HN
- 8Nex, a lexer similar to Lex/Flex that generates Go code3 people · 7 points · first shared 2014 · discussion on HN
- 9J for Haskell Programmers3 people · 3 points · first shared 2016 · discussion on HN
- 10Get a Brain: Build a neural network from scratch2 people · 4 points · first shared 2018 · discussion on HN
- 11Solving the Halting Problem2 people · 3 points · first shared 2021 · discussion on HN
- 12Ioccc2 people · first shared 2023
- 13Why Learn Haskell? (2018)1 people · 207 points · first shared 2021 · 113 comments on HN
- 14C vs GO1 people · 202 points · first shared 2012 · 175 comments on HN
- 15Get a Life1 people · 176 points · first shared 2021 · 21 comments on HN
What HN people wrote when they linked it
username223 · 2025-10-23
> https://crypto.stanford.edu/~blynn/compiler/ioccc.html
Good stuff -- thanks for sharing. IOCCC, like Perl Golf, is brilliantly absurd.
https://www.perlmonks.org/?node_id=759963
tromp · 2024-09-06
Between lambda calculus and LISP, I find LISP to be the ugly one, not only because of its far greater complexity, but also its lack of referential transparency. David Turner / Ben Lynn make some good observations about LISP in section "History versus myth" of [1]. If lack of types is what you dislike of the plain lambda calculus, then Haskell is a much better solution than LISP.
[1] https://crypto.stanford.edu/~blynn/lambda/lisp.html
dunham · 2023-03-03
One of my favorites is the self-hosting Haskell compiler from the 2019 IOCCC: https://www.ioccc.org/2019/lynn/hint.html
There is a series of articles on how it was built here: https://crypto.stanford.edu/~blynn/compiler/
FullyFunctional · 2021-10-08
Just 2 0 0 0 lines?!? That's really saying something. I wish it was available on macOS.
OT: I've falling back in love with Haskell after reading Ben Lynn's astonishing adventures (https://crypto.stanford.edu/~blynn/compiler/) and it's still super awesome for explorative programming.
siraben · 2021-03-01
Reading Ben Lynn's Haskell website was one of the things that got me out of a rut with learning Haskell and showed me how expressive, yet concise it is. There's a lot of advanced and beginner Haskell resources but not much intermediate. I highly recommend his Haskell series, Lambda Calculus series[1] and (my favorite) compiler for Haskell series[2].
It's as if SICP were redone in Haskell in the 21st century.
[1] https://crypto.stanford.edu/~blynn/lambda/
[2] https://crypto.stanford.edu/~blynn/compiler/
jjice · 2021-03-01
The lambda calculus section of this site helped me so much in my Language Theory course last semester. I highly recommend a look through if you're interested in the basic of computation and types.
https://crypto.stanford.edu/~blynn/lambda/
scottlocklin · 2020-03-09
Finance uses it because it's great for sorting out medium-big time oriented data. The IQ test aspect of it is probably considered a bonus in some shops.
There are non-terse APLs out there; the most obvious one floating around is Nial[1]. Culturally though, once you've figure out how to read and write in the compressed ascii runes, it's kind of hard to go back to the other way. J is actually denser because of the hooks, forks[2], rank and full tacit aspect of things. Personally whenever I've composed an algorithm in J I feel like I really understand it in a way that pretty much nothing else gives me with all the extra typing.
[1] https://github.com/danlm/qnial7
[2] https://crypto.stanford.edu/~blynn/c/apl.html
eesmith · 2019-12-16
I'm going to guess this was posted because https://news.ycombinator.com/item?id=21792763 linked to https://crypto.stanford.edu/~blynn/c/apl.html which commented "APL is the Classical Chinese of programming languages. ... Lengthy prose written in Classical Chinese, though minimalist and beautiful, is hard to read. While there are many great classical Chinese poems, there are only Four Great Classical Novels." linking in turn to the same Wikipedia page as this posting.
eggy · 2019-05-28
I would think Clojure vs. Java would be used given immutability. I like both Haskell and Racket for math, especially this article on geometric algebra with Haskell:
https://crypto.stanford.edu/~blynn/haskell/ga.html
I am personally learning Shen[1] because Lisp, optional typing (great type system), and the formal work done within it, and for it in proving, verification and other related endeavors. It seems to tick the Haskell, Lisp, Prolog and logic boxes for me. Its portability is great[2], however, it is still young and building libraries. I am thinking on trying to mimic the DL work done by Dragan Djuric[3] for Clojure in Shen. We'll see how that goes...
[1] http://www.shenlanguage.org/
[2] https://shen-language.github.io/
[3] https://dragan.rocks/
rafael859 · 2018-11-02
I've played around a bit with geometric algebra in the past year, and I have to say that by far the best resource (albeit a bit short) was Ben Lynn's implementation in Haskell [0]. Unfortunately there isn't a well-written source that explains the methods well. There are multiple ways to do things, and I had trouble finding elegant solutions to practical problems.
[0] https://crypto.stanford.edu/~blynn/haskell/ga.html
raphlinus · 2017-11-26
See also Ben Lynn's implementation[1] in about 100 lines of Haskell. Admittedly it's not a totally fair comparison because it's relying on Haskell's runtime, but it's still an excellent demonstration of Haskell's power and expressiveness compared with a lower level language.
[1]: https://crypto.stanford.edu/~blynn/lambda/lisp.html
reacweb · 2017-10-03
"C is the desert island language". see http://crypto.stanford.edu/~blynn/c/intro.html
For me, Linux is a huge development environment dedicated to C programming. Chapter 2 and 3 of manual pages gives C api. C gives the most direct access to kernel. IMHO we should try to find a replacement for C and the first target for this language should be linux kernel. If you can conceive a language that Linus Torvalds accepts, the rest of the planet will follow ;-)
st3fan · 2009-12-18
The first section I looked at contains a buffer overflow:
http://crypto.stanford.edu/~blynn/c/ch03.html#_when_are_size_0_arrays_…
Great C craft :-)
smabie · 2020-08-16
I think there's a conflict between the essence of array languages (building a DAG of monadic (in the FP sense) operations and letting arrays flow through it) and the one dimensionality of a stream of symbols in a text file. Ben Lynn [https://crypto.stanford.edu/~blynn/c/apl.html] puts it best:
"Worse still, tacit hooks, forks, and ranks obscures the beautiful category theory connections: hooks and forks are function composition and application within the Reader monad, while adjusting the rank of a function corresponds to applying functors."
Hooks are a structured approach to this problem, while stacks are an unstructured one. And there will always be tension between the two for as long as the current textual model of programming is used (or maybe no matter what representation we use). How obscure are we willing to get in order to get closer to the beautiful DAG we have in our head?
I of course don't have a good answer to that, and I think the dominant paradigm of array languages has set to be discovered. APL gets us close, but we clearly agree that there's more work yet to be done.
Looking at your bytecode design, I was reminded of this old paper about building APL hardware: http://www.softwarepreservation.org/projects/apl/Papers/197002_An%20AP… . Not sure how relavent that is, but maybe it'll be the inspiration of a beautiful VM architecture!
codethief · 2024-09-15
At least in simply-typed lambda calculus it's not possible, see also https://crypto.stanford.edu/~blynn/lambda/simply.html :
> This implies the Y combinator and omega combinator cannot be expressed in this system. […] In other words, programs always halt.
I assume the reason you can still write down the type in Haskell (as in your example further down) is that Haskell types include the bottom?
mannykannot · 2022-11-09
I was going to say I had heard that this was the intention of Lisp's creators, then I thought I had better check, and immediately found this:
Lisp had assignments and goto before it had recursion, and started as a dialect of Fortran! It was only later that Lisp programmers investigated the benefits of pure functions. Lisp was not based on lambda calculus, but rather Kleene's work on recursive functions. At the time, McCarthy had heard of lambda calculus but had not yet studied it!
https://crypto.stanford.edu/~blynn/lambda/lisp.html
archibaldJ · 2021-10-18
this is super cool; I wonder if some of the concepts can be applied in building Codex pipeline
just found https://crypto.stanford.edu/~blynn/haskell/jfh.html to cross-ref stuff when I get lost
mrslave · 2021-03-02
Filling in your [0]th link. Thank you so much for this pointer.
[0] https://crypto.stanford.edu/~blynn/haskell/
ukj · 2020-03-27
So as a brief summary: laziness leaks time. Whether that's a good or a bad thing depends on what you want/need. It may be a bad thing if you are doing cryptography because time leaks allow side-channel attacks ( https://en.wikipedia.org/wiki/Timing_attack ).
As with all philosophical squabbles - there are arguments for each side. It's up to you to make up your mind based on your particular use-case.
And so in context of crypto + Haskell, have a look at these two posts:
https://crypto.stanford.edu/~blynn/c/haskell.html
https://crypto.stanford.edu/~blynn/haskell/lazy.html
SquishyPanda23 · 2019-07-14
Independently of the connection between PG and Lisp, many engineers are interested in Lisp because it's one of the simplest programming languages that is closely connected to the Lambda calculus.
E.g. https://crypto.stanford.edu/~blynn/lambda/lisp.html
infinity0 · 2018-11-03
The way this text does the geometric product is trying to be intuitive by immediately giving a "physical" interpretation as the sum of the inner and outer products. However the physical interpretations breaks down when trying to multiply three of these together.
I think Ben Lynn's approach is actually better: https://crypto.stanford.edu/~blynn/haskell/ga.html (Part 1)
It starts off more abstract, defining the geometric product simply as string concatenation (as in "free monoid" if you're familiar with that term, which you would if you have intermediate Haskell knowledge) plus a very natural constraint. From this natural constraint one can then deduce the sum-based interpretation that the OP gives.
The natural constraint is then further generalised and justified in more detail in Part 3: https://crypto.stanford.edu/~blynn/haskell/cga.html
shadowmint · 2012-06-14
Judging by the similarity to his much large section on C (http://crypto.stanford.edu/~blynn/c/) I'd say serious.
Also, who cares what his style is?
If _you_ ever have to work on the code, run gofmt on it; if that's how he likes his go, good for him.
wyager · 2024-06-15
> unit quaternions also don’t form a vector space
Unit quaternions are the lie group. If you want something you can add willy-nilly, you want the lie algebra of all quaternions, which represent rotational velocities, just as axis-angle represents rotational velocities.
Comparing unit quaternions to axis-angle is a bit of a category error - it would be more appropriate to compare unit quaternions to rotation matrices, and all quaternions to axis-angle.
> One advantage of using quaternions is how easy the exponential map is to compute—if you don’t need a rotation matrix, it’s a good option.
You rarely need a rotation matrix at all when using quaternions. As mentioned in the article, you can compute rotations using `pqp^-1`.
I think the easiest way to understand quaternions is just to read about geometric algebra. It took hundreds of years to invent quaternions, but once you understand geometric algebra (which is shockingly simple), you can invent quaternions in just a few minutes. I found this article to be a good intro several years ago: https://crypto.stanford.edu/~blynn/haskell/ga.html
jart · 2022-03-15
It's a good question, if we consider that it's been unanswered on the computer science stack exchange for four years. https://cs.stackexchange.com/questions/83533/practical-usage-of-the-%C…
Basically, it does beta normal form reduction. In these kinds of situations, I sometimes feel like it's just as valuable to know how to get the darn thing to run, and then the rest explains itself. So for the purposes of this explanation, I'll share a Hello World example for this interpreter, that should hopefully get you going. This won't cover beta reduction or any of that jazz. Just the simplest possible usage that you can type into the web page at https://crypto.stanford.edu/~blynn/lambda/ and see something happen.
(\a.(\b.a(b b))(\b.a(b b)))(\a.\b.b(\c.c)(\c.\d.a c(a d))(\c.\d.a(c d)))(\a.\b.\c.c(\d.\e.\f.\g.e d))
# a.k.a. Y(λab.b(λc.c)(λcd.ac(ad))(λcd.a(cd)))(λabc.c(λdefg.ed))
# a.k.a. [[Y λλ [[[0 λ 0] λλ [[3 1] [3 0]]] λλ [3 [1 0]]]] λλλ [0 λλλλ [2 3]]]
It should spit out the identity function:
λd.d
Why did this happen? It's because Y(λab.b(λc.c)(λcd.ac(ad))(λcd.a(cd))) is the reducer a.k.a. E and λabc.c(λdefg.ed) is the argument. What is λabc.c(λdefg.ed)? It's an encoded version of the identity function λd.d. So in other words, all it did was output exactly what was inputted. Except the input had to be encoded. Why is it encoded? Normally in LISP, if we wanted to pass a program to a self-interpreter, we've wrap…
bmc7505 · 2022-02-25
> "What are recent developments in linear algebra?"
Have you heard of geometric algebra? It takes a while to wrap your head around, but unifies a lot of mathematics in a very elegant way. For instance, you can view Euclidean geometry as a special case, and concepts like quaternions and rotations can be explained in a very natural way. There are a few good resources below if you're interested.
[0]: http://geometry.mrao.cam.ac.uk/2020/06/euclidean-geometry-and-geometri…
[1]: https://www.youtube.com/watch?v=ipqKvNHnABs
[2]: https://alexkritchevsky.com/2020/10/15/ea-operations.html
[3]: https://www.youtube.com/playlist?list=PLpzmRsG7u_gqaTo_vEseQ7U8KFvtiJY…
[4]: https://crypto.stanford.edu/~blynn/haskell/ga.html
[5]: https://bivector.net/
snaky · 2016-06-18
Yes.
"J for Haskell Programmers" - http://crypto.stanford.edu/~blynn/haskell/jfh.html
Talking about data analysis
"Data Analysis using J" - http://csilo.com/static/DataAnalysisWithJ.html
J for IPython - https://github.com/Synthetica9/JMagic, https://github.com/adrian17/jkernel
and there's https://www.reddit.com/r/apljk/