mirror of
https://github.com/GrammaticalFramework/gf-core.git
synced 2026-05-24 02:12:50 -06:00
Transfer: reimplement operators with type classes.
This commit is contained in:
@@ -1,18 +1,24 @@
|
||||
import prelude
|
||||
|
||||
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)
|
||||
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 -> Int
|
||||
natToInt : Nat -> Integer
|
||||
natToInt Zero = 0
|
||||
natToInt (Succ n) = 1 + natToInt n
|
||||
|
||||
intToNat : Int -> Nat
|
||||
intToNat : Integer -> Nat
|
||||
intToNat n = if n == 0 then Zero else Succ (intToNat (n-1))
|
||||
|
||||
Reference in New Issue
Block a user