3 ms·
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
by twanvl 10y ago
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.