30 lines
562 B
Text
30 lines
562 B
Text
-- Peano naturals
|
|
data Nat where
|
|
Zero : Nat
|
|
Succ : Nat -> Nat
|
|
|
|
toInt : Nat -> Int
|
|
toInt a = case a of
|
|
Succ n => 1 + toInt n
|
|
Zero => 0
|
|
|
|
fromInt a = case a of
|
|
0 => Zero
|
|
n => Succ (fromInt (a - 1))
|
|
|
|
-- Peano arithmetic --
|
|
|
|
-- Peano addition
|
|
add : Nat -> Nat -> Nat
|
|
add left right = case left of
|
|
Zero => right
|
|
Succ n => Succ (add n right)
|
|
|
|
-- Peano multiplication
|
|
mul : Nat -> Nat -> Nat
|
|
mul left right = case right of
|
|
Zero => Zero
|
|
Succ n => add left (mul left n)
|
|
|
|
-- Returns 10_000
|
|
main = toInt (mul (fromInt 100) (fromInt 100))
|