summaryrefslogtreecommitdiff
path: root/gf-book/examples/chapter6/Arithm.gf
blob: 685627745dfd02b4bc4a93f26bfb0b3ba9020082 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
abstract Arithm = {
  cat
    Prop ;                        -- proposition
    Nat ;                         -- natural number
  data
    Zero : Nat ;                  -- 0
    Succ : Nat -> Nat ;           -- the successor of x
  fun
    Even : Nat -> Prop ;          -- x is even
    And  : Prop -> Prop -> Prop ; -- A and B

  cat Less Nat Nat ; 
  data LessZ : (y : Nat) -> Less Zero (Succ y) ;
  data LessS : (x,y : Nat) -> Less x y -> Less (Succ x) (Succ y) ;

  cat Span ;
  data FromTo : (m,n : Nat) -> Less m n -> Span ;

  fun one : Nat ;
  def one = Succ Zero ;

  fun twice : Nat -> Nat ;
  def twice x = plus x x ;

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

}