Skip to content

Instantly share code, notes, and snippets.

@Sam-Serpoosh
Last active October 23, 2016 04:56
Show Gist options
  • Save Sam-Serpoosh/41edff467a162d5d5bf3c28d95b8ffa0 to your computer and use it in GitHub Desktop.
Save Sam-Serpoosh/41edff467a162d5d5bf3c28d95b8ffa0 to your computer and use it in GitHub Desktop.
PRED/SUB1 function implemented in pure Lambda Calculus using Haskell!
zero = \f -> \x -> x
mySucc = \n -> \f -> \x -> f $ n f x
add = \n -> \m -> n mySucc m
mkPair = \a -> \b -> \s -> s a b
myFst = \a -> \b -> a
mySnd = \a -> \b -> b
step = \p -> mkPair (p mySnd) (mySucc (p mySnd))
nSteps = \n -> \p -> n step p
zz = mkPair zero zero
myPred = \n -> (nSteps n zz) myFst
one = mySucc zero
two = mySucc (mySucc zero)
three = mySucc (mySucc (mySucc zero))
six = add (add two three) one
main :: IO ()
main = do
let p = mkPair two three
let n = nSteps three p
putStrLn $ show $ (myPred six) (\x -> x + 1) 0 -- => 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment