summaryrefslogtreecommitdiff
path: root/transfer/examples/nat.tr
blob: cd9101574c74bb874122f29da5746493d2b676a2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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

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

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