summaryrefslogtreecommitdiff
path: root/book/examples/chapter6
diff options
context:
space:
mode:
authoraarne <aarne@chalmers.se>2010-11-22 15:48:52 +0000
committeraarne <aarne@chalmers.se>2010-11-22 15:48:52 +0000
commit67176f1520d8ac68a00b5266092fcd31a82f4bd8 (patch)
tree6309b8ccfedb458fec7f9772e01b496975e0389f /book/examples/chapter6
parent76ba03b545600054176612201de78dca16eb65e1 (diff)
completed book examples
Diffstat (limited to 'book/examples/chapter6')
-rw-r--r--book/examples/chapter6/Arithm.gf30
-rw-r--r--book/examples/chapter6/ClassesEng.gf4
-rw-r--r--book/examples/chapter6/Smart.gf16
3 files changed, 48 insertions, 2 deletions
diff --git a/book/examples/chapter6/Arithm.gf b/book/examples/chapter6/Arithm.gf
new file mode 100644
index 000000000..685627745
--- /dev/null
+++ b/book/examples/chapter6/Arithm.gf
@@ -0,0 +1,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) ;
+
+}
diff --git a/book/examples/chapter6/ClassesEng.gf b/book/examples/chapter6/ClassesEng.gf
index a282bd87a..5bdf80c35 100644
--- a/book/examples/chapter6/ClassesEng.gf
+++ b/book/examples/chapter6/ClassesEng.gf
@@ -18,8 +18,8 @@ lin
Fan = mkCN (mkN "fan") ;
Switchable, Dimmable = <> ;
- SwitchOn = mkV2 (mkV "on" (mkV "switch")) ;
- SwitchOff = mkV2 (mkV "off" (mkV "switch")) ;
+ SwitchOn = mkV2 (partV (mkV "switch") "on") ;
+ SwitchOff = mkV2 (partV (mkV "switch") "off") ;
Dim = mkV2 (mkV "dim") ;
switchable_Light = <> ;
diff --git a/book/examples/chapter6/Smart.gf b/book/examples/chapter6/Smart.gf
new file mode 100644
index 000000000..6fc3e0bc5
--- /dev/null
+++ b/book/examples/chapter6/Smart.gf
@@ -0,0 +1,16 @@
+abstract Smart = {
+
+ cat
+ Command ;
+ Kind ;
+ Device Kind ;
+ Action Kind ;
+
+ fun
+ Act : (k : Kind) -> Action k -> Device k -> Command ;
+ The : (k : Kind) -> Device k ; -- the light
+ Light, Fan : Kind ;
+ Dim : Action Light ;
+ SwitchOn, SwitchOff : (k : Kind) -> Action k ;
+
+}