Skip to content

Instantly share code, notes, and snippets.

@Heimdell
Last active August 29, 2015 14:01
Show Gist options
  • Save Heimdell/ed7d5568fdc118e78ca8 to your computer and use it in GitHub Desktop.
Save Heimdell/ed7d5568fdc118e78ca8 to your computer and use it in GitHub Desktop.
Proof, that lists could be modelled as functions.
{-# 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