Created
March 18, 2014 18:47
-
-
Save passy/9626721 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Peano where | |
data Nat = Zero | |
| Succ Nat | |
deriving (Show, Read, Eq) | |
isZero :: Nat -> Bool | |
isZero Zero = True | |
isZero (Succ _) = False | |
predecessor :: Nat -> Nat | |
predecessor Zero = undefined | |
predecessor (Succ n) = n | |
successor :: Nat -> Nat | |
{- successor n = Succ n -} | |
successor = Succ | |
plus :: Nat -> Nat -> Nat | |
plus Zero n = n | |
plus (Succ n) o = successor $ n `plus` o | |
minus :: Nat -> Nat -> Nat | |
minus Zero Zero = Zero | |
minus Zero (Succ _) = undefined | |
minus n@(Succ _) Zero = n | |
minus (Succ n) (Succ o) = n `minus` o |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment