forked from GitHub/gf-core
Transfer: Changed transfer program file extension from .tr to .tra to avoid collision with Troff file extension.
This commit is contained in:
24
transfer/lib/nat.tra
Normal file
24
transfer/lib/nat.tra
Normal file
@@ -0,0 +1,24 @@
|
||||
import prelude
|
||||
|
||||
data Nat : Type where
|
||||
Zero : Nat
|
||||
Succ : (n:Nat) -> Nat
|
||||
|
||||
add_Nat : Add Nat
|
||||
add_Nat = rec zero = Zero
|
||||
plus = natPlus
|
||||
|
||||
natPlus : Nat -> Nat -> Nat
|
||||
natPlus Zero y = y
|
||||
natPlus (Succ x) y = Succ (natPlus x y)
|
||||
|
||||
pred : Nat -> Nat
|
||||
pred Zero = Zero
|
||||
pred (Succ n) = n
|
||||
|
||||
natToInt : Nat -> Integer
|
||||
natToInt Zero = 0
|
||||
natToInt (Succ n) = 1 + natToInt n
|
||||
|
||||
intToNat : Integer -> Nat
|
||||
intToNat n = if n == 0 then Zero else Succ (intToNat (n-1))
|
||||
Reference in New Issue
Block a user