peano.hs 433 B

123456789101112131415161718
  1. -- Slide 28
  2. data Nat = Zero | Succ Nat deriving Show
  3. intValOf thisNat = case thisNat of
  4. Zero -> 0
  5. Succ nextNat -> 1 + intValOf nextNat
  6. natValOf thisInt = if thisInt == 0 then Zero else Succ (natValOf (thisInt - 1))
  7. addition aNat tinyNat = case tinyNat of
  8. Zero -> aNat
  9. Succ tinierNat -> Succ (addition aNat tinierNat)
  10. additiont aNat tinyNat = case tinyNat of
  11. Zero -> aNat
  12. Succ tinierNat -> additiont (Succ aNat) tinierNat