I\'m attempting to implement church numerals in Haskell, but I\'ve hit a minor problem. Haskell complains of an infinite type with
Occurs check: cannot construct th
I have encountered the same problem. And I solved it without adding type signature.
Here's the solution, with cons car copied from SICP.
cons x y = \m -> m x y
car z = z (\p q -> p)
cdr z = z (\p q -> q)
next z = cons (cdr z) (succ (cdr z))
pred n = car $ n next (cons undefined zero)
sub m n = n pred m
You can find full source here.
I'm really amazed after writing sub m n = n pred m, and load it in ghci without type error!
Haskell code is so concise! :-)