Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module PeanoSum where
- -- Written by Marcelo Camargo <marcelocamargo@linuxmail.org> on
- -- Sat Oct 22 2016
- -- Represent natural numbers
- data Nat = Zero
- | Succ Nat
- -- Let neutral element of Monoid be id
- -- Let (Functor a) b become Functor (a .+. b)
- infixl .+.
- (.+.) :: Nat -> Nat -> Nat
- (.+.) Zero b = b
- (.+.) (Succ a) b = Succ ((.+.) a b)
- -- Built only for visual representation with pipes
- instance Show Nat where
- show Zero = ""
- show (Succ n) = "|" ++ (show n)
- -- Create aliases for 1 up to 9
- zero, one, two, three, four, five, six, seven, eight, nine :: Nat
- zero = Zero
- one = Succ zero
- two = Succ one
- three = Succ two
- four = Succ three
- five = Succ four
- six = Succ five
- seven = Succ six
- eight = Succ seven
- nine = Succ eight
- -- Test our function definitions with pipes
- main = putStrLn . show $ eight .+. nine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement