list via codensity
Jan. 8th, 2017 12:49 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
List a = Codensity Endo a = forall r. (a -> r -> r) -> r -> r
nil :: List a
nil = \f z -> z
cons :: a -> List a -> List a
cons x xs = \f z -> f x (xs f z)
append :: List a -> List a -> List a
append xs ys = \f z -> xs f (ys f z)
foldr :: (a -> r -> r) -> r -> List a -> r
foldr f z xs = xs f z
Basically, it's like lambda.
Src: https://golem.ph.utexas.edu/category/2012/09/where_do_monads_come_from.html#c042100