KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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 the infinite type: t = (t -> t1) -> (t1 -> t2) -> t2 when I try and do subtraction. I'm 99% positive that my lambda calculus is valid (although if it isn't, please tell me). What I want to know, is whether there is anything I can do to make haskell work with my functions. module Church where type (Church a) = ((a -> a) -> (a -> a)) makeChurch :: Int -> (Church a) makeChurch 0 = \f -> \x -> x makeChurch n = \f -> \x -> f (makeChurch (n-1) f x) numChurch x = (x succ) 0 showChurch x = show $ numChurch x succChurch = \n -> \f -> \x -> f (n f x) multChurch = \f2 -> \x2 -> \f1 -> \x1 -> f2 (x2 f1) x1 powerChurch = \exp -> \n -> exp (multChurch n) (makeChurch 1) predChurch = \n -> \f -> \x -> n (\g -> \h -> h (g f)) (\u -> x) (\u -> u) subChurch = \m -> \n -> (n predChurch) m
Tags (comma-separated)
Save Edits
Cancel