
Whiteboard problems in pure Lambda Calculus - jtolds
http://www.jtolds.com/writing/2017/03/whiteboard-problems-in-pure-lambda-calculus/
======
kazagistar
I'm confused by their "3 part linked list". I always thought the elegance of
lambda calculus was that each data structure was equivalent to the method by
which you use it. A boolean _is_ a function that does a conditional statement.
A number _is_ a function that does a loop. So logically, a list _is_ a
function that does a fold, like "LIST :: (a -> b -> a) -> a -> a".

~~~
twanvl
There are many different ways to encode lists. You are using the Church
encoding, where a value is a fold,

    
    
        nil = λn.λc.n
        cons = λx.λxs.λn.λc.c x (xs n c)
        fold = λf.λz.λxs.xs z f
    

Another option is the Scott encoding, where a value is a case distinction

    
    
        nil = λn.λc.n
        cons = λx.λxs.λn.λc.c x xs
        fold = Y (λfold.λf.λz.λxs.xs z (λhead.λtail.f head (fold f z tail)))
    

And then there is the 3-tuple thing proposed in the article.

------
tombert
It's things like this that make me wonder what the world would be like if we
had embraced the Church-style Lambda Calculus model instead of the Turing
system. I don't know if it would be better or worse, but I think it's an
interesting thought experiment.

------
codezero
I've been wondering why a lot of things are the way they are in functional
programming, not being very lambda inclined myself, I didn't seek it out, but
this post summarized a lot that has been on my mind lately.

In particular, and with apologies for being so clueless – it never occurred to
me why currying was necessary – I didn't realize lambda calculus required
functions to take only one argument. With that limitation, currying is genius.

------
runeblaze
Tangential book recommendation: I have found the first chapters of "Type
Theory and Formal Proof" a great in-depth introduction into lambda calculus
and its typed variations.

~~~
frostirosti
This is a jump straight into the deep end. I can't recommend starting here.
"How to prove it" [https://www.amazon.com/How-Prove-Structured-
Approach-2nd/dp/...](https://www.amazon.com/How-Prove-Structured-
Approach-2nd/dp/0521675995) would be a much more appropriate start

~~~
SAI_Peregrinus
Naw, straight into the deep end is to start with reading the Homotopy Type
Theory book...
[https://homotopytypetheory.org/book/](https://homotopytypetheory.org/book/)

------
tempodox
Thou shalt not make use of French if thou doest not know the language. Deaux
is a village in France (you can google it).

~~~
draw_down
> Thou shalt not make use of French if thou doest not know the language.

The ironing is delicious.

~~~
OJFord
The washing's even better.

------
MBlume
A while ago I wrote a Brainfuck interpreter in lambda calculus. I abused the
Clojure macro system to make my job a little easier, and of course, I wrapped
it in an interface that could do IO, but this does compile to a single pure
lambda calculus function which takes a (church encoded) brainfuck program and
input string and returns an output string.

[https://github.com/MichaelBlume/lambdafuck/blob/master/src/l...](https://github.com/MichaelBlume/lambdafuck/blob/master/src/lambdafuck/core.clj)

~~~
tromp
I also wrote one at

[http://tromp.github.io/cl/Binary_lambda_calculus.html#Brainf...](http://tromp.github.io/cl/Binary_lambda_calculus.html#Brainfuck)

to demonstrate the invariance theorem.

------
davidgrenier
I often feel that Alan gets adequate credit but Alonzo too little. There must
be something I don't get.

~~~
fmap
Turing gets more credit in popular culture, but academically Church is more
influential. Just look at the list of Church's PhD students:
[http://www.genealogy.ams.org/id.php?id=8011](http://www.genealogy.ams.org/id.php?id=8011)

I have no clue why Turing became such a pop-culture icon, though...

~~~
krapp
Turing doesn't really have the status of a pop-culture icon. Outside of the
phrase "Turing complete", and maybe historical accounts around breaking the
Enigma, I doubt most people have even heard of him.

He's definitely more known than Alonzo Church, though.

~~~
lou1306
What about "The Imitation Game"? I suppose that movie made Turing a quite well
known figure, especially viz. Church.

------
lisper
Factorials in pure lambda calculus:

[http://www.flownet.com/ron/lambda-
calculus.html](http://www.flownet.com/ron/lambda-calculus.html)

------
kelvin0
See, the original post about white boarding in LISP was original with certain
humor to it.

I can't say this was even close in terms of enjoyment or originality. Maybe I
missed the point?

~~~
justinhj
I don't think I saw it as an attempt to be original or funny. It's more
interesting and educational in that it shows how to do build up a simple
program from the very limited operations of lands calculus.

------
brandonaaskov
Another tangential reading recommendation: I only started reading about Lambda
Calculus a few days ago. The Imposter's Handbook does a good job covering it,
but also praises this medium article that's super helpful (and also explains
the y combinator): [https://medium.com/@ayanonagon/the-y-combinator-no-not-
that-...](https://medium.com/@ayanonagon/the-y-combinator-no-not-that-
one-7268d8d9c46#.m4mobqry9)

------
kovrik
Reminded me about good old [https://codon.com/programming-with-
nothing](https://codon.com/programming-with-nothing)

------
kowdermeister
> Anyway, here’s fizz buzz in pure lambda calculus:

Serious question: if the code is legit and can't be simplified any shorter
(like you could in any C style lang), can we consider lambda calculus the
string theory of programming? By that I mean lots of work for little gain (as
it turned out to be nowadays) ((I know it has gains in other fields)).

I can imagine it like an assembly like compile target and it can explain the
verboseness.

~~~
jtolds
Oh, it definitely can be simplified a bunch. There's all sorts of stuff to
prune out. I didn't even attempt to try and code golf at all. There's library
definitions included in that snippet that probably aren't needed.

------
stan_rogers
The same thing, but in Ruby stabby-proc notation (from 2012) by Tom Stuart:

[https://www.youtube.com/watch?v=VUhlNx_-
wYk](https://www.youtube.com/watch?v=VUhlNx_-wYk)

Well, perhaps not _exactly_ the same thing, but only because Ruby requires the
Z-combinator due to applicative order.

------
platz
Instead of pure lambda calculus, another less severe route would be to simply
restrict yourself to Church-encoded or Scott-encoded formulations of data
structures.

~~~
arethuza
And a more severe route would be to allow just S and K.

~~~
SAI_Peregrinus
Just use Lazy K:
[https://tromp.github.io/cl/lazy-k.html](https://tromp.github.io/cl/lazy-k.html)

------
empath75
I love this so much.

------
dogfishbar
Nice article! But you have a typo.

(λx.x y)

does not return y, though

(\x.x) y

does.

~~~
jtolds
There's an aside about how I've chosen precedence. The way I've defined
operator precedence and binding, (\x.x) y is not a valid expression
(parentheses _only_ mean function application), and (λx.x y) returns y. You
can argue I defined things wrong, but it is all in how you define things.

