summaryrefslogtreecommitdiff
path: root/transfer/examples/nat.tr
blob: c529e52383f7fc6e938a026b4802ba959785da8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
data Nat : Type where
	Zero : Nat
  	Succ : (n:Nat) -> Nat

plus : Nat -> Nat -> Nat
plus Zero y = y
plus (Succ x) y = Succ (plus x y)

pred : Nat -> Nat
pred Zero = Zero
pred (Succ n) = n

natToInt : Nat -> Int
natToInt Zero = 0
natToInt (Succ n) = 1 + natToInt n

intToNat : Int -> Nat
intToNat n = if n == 0 then Zero else Succ (intToNat (n-1))