Skip to content

Instantly share code, notes, and snippets.

@robertpfeiffer
Created May 29, 2010 17:16
Show Gist options
  • Save robertpfeiffer/418386 to your computer and use it in GitHub Desktop.
Save robertpfeiffer/418386 to your computer and use it in GitHub Desktop.
Prelude> let church n f = foldl (.) id (map (\x -> f) [1..n])
Prelude> let unchurch fun = fun (+1) 0
Prelude> let mul = (.)
Prelude> let exp a b = ($) b a
Prelude> let exp2 m n f x = n m f x
Prelude> :t exp2
exp2 :: t -> (t -> t1 -> t2 -> t3) -> t1 -> t2 -> t3
Prelude> let exp1 m n = n m
Prelude> :t exp1
exp1 :: t -> (t -> t1) -> t1
Prelude> unchurch $ exp1 (church 2) (church 0)
1
Prelude> unchurch $ exp2 (church 2) (church 0)
1
Prelude> let exp3 a b f x = b (mul a) (church 1) f x
Prelude> unchurch $ exp3 (church 2) (church 0)
1
Prelude> :t exp3
exp3
:: (b -> c)
-> (((a -> b) -> a -> c)
-> ((a1 -> a1) -> a1 -> a1)
-> t
-> t1
-> t2)
-> t
-> t1
-> t2
Prelude> let exp4 a b f x = b (mul a) (church 1) f x
Prelude> unchurch $ exp4 (church 2) (church 0)
1
Prelude> :t exp4
exp4
:: (b -> c)
-> (((a -> b) -> a -> c)
-> ((a1 -> a1) -> a1 -> a1)
-> t
-> t1
-> t2)
-> t
-> t1
-> t2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment