fork(1) download
  1. module Main where
  2.  
  3. import Prelude hiding ((+), (*), (^))
  4.  
  5. data N = Z | S N
  6. deriving (Eq, Show)
  7.  
  8. h :: N -> N -> N -> N
  9. h Z _ b = S b
  10. h (S Z) a Z = a
  11. h (S (S Z)) _ Z = Z
  12. h _ _ Z = S Z
  13. h (S n) (S a) (S b) = h n (S a) (h (S n) (S a) b)
  14.  
  15. (+) :: N -> N -> N
  16. (+) = h (S Z)
  17.  
  18. (*) :: N -> N -> N
  19. (*) = h (S (S Z))
  20.  
  21. (^) :: N -> N -> N
  22. (^) = h (S (S (S Z)))
  23.  
  24. main = print ((S (S Z)) + (S (S (S Z)))) >>
  25. print ((S (S Z)) * (S (S (S Z)))) >>
  26. print ((S (S Z)) ^ (S (S (S Z))))
Success #stdin #stdout 0s 4532KB
stdin
Standard input is empty
stdout
S (S (S (S (S Z))))
S (S (S (S (S (S Z)))))
S (S (S (S (S (S (S (S Z)))))))