Last active
August 29, 2015 14:01
-
-
Save Heimdell/ed7d5568fdc118e78ca8 to your computer and use it in GitHub Desktop.
Proof, that lists could be modelled as functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE RankNTypes #-} | |
type List a = | |
forall b. | |
(a -> b -> b) -> (b -> b) | |
nil :: List a | |
nil _ a = a | |
infixr 5 >< | |
(><) :: a -> List a -> List a | |
(x >< xs) f def = | |
x `f` xs f def | |
dump :: Show a => List a -> String | |
dump list = | |
list attach "nil" | |
where | |
attach x acc = show x ++ " >< " ++ acc | |
main = print $ dump $ 1 >< 2 >< 3 >< 4 >< 5 >< nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment