summaryrefslogtreecommitdiff
path: root/book/examples/chapter6
diff options
context:
space:
mode:
authoraarne <aarne@chalmers.se>2010-11-22 12:55:37 +0000
committeraarne <aarne@chalmers.se>2010-11-22 12:55:37 +0000
commit76ba03b545600054176612201de78dca16eb65e1 (patch)
tree5615286b239bee637b32465e9cbf36807ab2c318 /book/examples/chapter6
parent0bf41793694e8b3101d09e34858eba8ab2c8c5b6 (diff)
started a subdir for the book
Diffstat (limited to 'book/examples/chapter6')
-rw-r--r--book/examples/chapter6/Aggregation.gf33
-rw-r--r--book/examples/chapter6/AggregationEng.gf17
-rw-r--r--book/examples/chapter6/Bin.gf50
-rw-r--r--book/examples/chapter6/Classes.gf28
-rw-r--r--book/examples/chapter6/ClassesEng.gf29
-rw-r--r--book/examples/chapter6/DShopping.gf24
-rw-r--r--book/examples/chapter6/DShoppingEng.gf33
-rw-r--r--book/examples/chapter6/Nat.gf22
-rw-r--r--book/examples/chapter6/Verbs.gf22
-rw-r--r--book/examples/chapter6/VerbsEng.gf22
10 files changed, 280 insertions, 0 deletions
diff --git a/book/examples/chapter6/Aggregation.gf b/book/examples/chapter6/Aggregation.gf
new file mode 100644
index 000000000..28cbd39ef
--- /dev/null
+++ b/book/examples/chapter6/Aggregation.gf
@@ -0,0 +1,33 @@
+abstract Aggregation = {
+ cat S ; NP ; VP ;
+ data
+ PredVP : NP -> VP -> S ;
+ ConjS : S -> S -> S ;
+ ConjVP : VP -> VP -> VP ;
+ ConjNP : NP -> NP -> NP ;
+ Run, Walk : VP ;
+ John, Mary : NP ;
+
+ fun aggr : S -> S ; -- main aggregation function
+ def aggr (ConjS (PredVP x X) (PredVP y Y)) =
+ ifS (eqNP x y)
+ (PredVP x (ConjVP X Y))
+ (ifS (eqVP X Y)
+ (PredVP (ConjNP x y) X)
+ (ConjS (PredVP x X) (PredVP y Y))) ;
+ fun ifS : Bool -> S -> S -> S ; -- if b then x else y
+ def
+ ifS True x _ = x ;
+ ifS False _ y = y ;
+ fun eqNP : NP -> NP -> Bool ; -- x == y
+ def
+ eqNP John John = True ;
+ eqNP Mary Mary = True ;
+ eqNP _ _ = False ;
+ fun eqVP : VP -> VP -> Bool ; -- X == Y
+ def
+ eqVP Run Run = True ;
+ eqVP Walk Walk = True ;
+ eqVP _ _ = False ;
+ cat Bool ; data True, False : Bool ;
+}
diff --git a/book/examples/chapter6/AggregationEng.gf b/book/examples/chapter6/AggregationEng.gf
new file mode 100644
index 000000000..9ed403c79
--- /dev/null
+++ b/book/examples/chapter6/AggregationEng.gf
@@ -0,0 +1,17 @@
+concrete AggregationEng of Aggregation = {
+
+lincat S, NP, VP = Str ;
+
+lin
+ PredVP x y = x ++ y ;
+ ConjS a b = a ++ "or" ++ b ;
+ ConjVP a b = a ++ "or" ++ b ;
+ ConjNP a b = a ++ "or" ++ b ;
+
+ Run = "runs" ;
+ Walk = "walks" ;
+ John = "John" ;
+ Mary = "Mary" ;
+
+}
+
diff --git a/book/examples/chapter6/Bin.gf b/book/examples/chapter6/Bin.gf
new file mode 100644
index 000000000..c181656f8
--- /dev/null
+++ b/book/examples/chapter6/Bin.gf
@@ -0,0 +1,50 @@
+abstract Bin = {
+
+cat Nat ; Bin ; Pos ;
+
+data
+ Zero : Nat ;
+ Succ : Nat -> Nat ;
+
+ BZero : Bin ; -- 0
+ BPos : Pos -> Bin ; -- p
+ BOne : Pos ; -- 1
+ AZero : Pos -> Pos ; -- p0
+ AOne : Pos -> Pos ; -- p1
+
+fun
+ bin2nat : Bin -> Nat ;
+def
+ bin2nat BZero = Zero ;
+ bin2nat (BPos p) = pos2nat p ;
+fun
+ pos2nat : Pos -> Nat ;
+def
+ pos2nat BOne = one ;
+ pos2nat (AZero p) = twice (pos2nat p) ;
+ pos2nat (AOne p) = Succ (twice (pos2nat p)) ;
+fun one : Nat ;
+def one = Succ Zero ;
+fun twice : Nat -> Nat ;
+def
+ twice Zero = Zero ;
+ twice (Succ n) = Succ (Succ (twice n)) ;
+
+fun
+ nat2bin : Nat -> Bin ;
+def
+ nat2bin Zero = BZero ;
+ nat2bin (Succ n) = bSucc (nat2bin n) ;
+fun
+ bSucc : Bin -> Bin ;
+def
+ bSucc BZero = BPos BOne ;
+ bSucc (BPos p) = BPos (pSucc p) ;
+fun
+ pSucc : Pos -> Pos ;
+def
+ pSucc BOne = AZero BOne ;
+ pSucc (AZero p) = AOne p ;
+ pSucc (AOne p) = AZero (pSucc p) ;
+
+} \ No newline at end of file
diff --git a/book/examples/chapter6/Classes.gf b/book/examples/chapter6/Classes.gf
new file mode 100644
index 000000000..ac7430d25
--- /dev/null
+++ b/book/examples/chapter6/Classes.gf
@@ -0,0 +1,28 @@
+abstract Classes = {
+
+flags
+ startcat = Command ;
+
+cat
+ Command ;
+ Kind ;
+ Class ;
+ Instance Class Kind ;
+ Action Class ;
+ Device Kind ;
+
+fun
+ Act : (c : Class) -> (k : Kind) -> Instance c k -> Action c -> Device k -> Command ;
+ The : (k : Kind) -> Device k ;
+
+ Light, Fan : Kind ;
+ Switchable, Dimmable : Class ;
+
+ SwitchOn, SwitchOff : Action Switchable ;
+ Dim : Action Dimmable ;
+
+ switchable_Light : Instance Switchable Light ;
+ switchable_Fan : Instance Switchable Fan ;
+ dimmable_Light : Instance Dimmable Light ;
+
+}
diff --git a/book/examples/chapter6/ClassesEng.gf b/book/examples/chapter6/ClassesEng.gf
new file mode 100644
index 000000000..a282bd87a
--- /dev/null
+++ b/book/examples/chapter6/ClassesEng.gf
@@ -0,0 +1,29 @@
+--# -path=.:present
+
+concrete ClassesEng of Classes = open SyntaxEng, ParadigmsEng in {
+
+lincat
+ Command = Utt ;
+ Kind = CN ;
+ Class = {} ;
+ Instance = {} ;
+ Action = V2 ;
+ Device = NP ;
+
+lin
+ Act _ _ _ a d = mkUtt (mkImp a d) ;
+ The k = mkNP the_Det k ;
+
+ Light = mkCN (mkN "light") ;
+ Fan = mkCN (mkN "fan") ;
+ Switchable, Dimmable = <> ;
+
+ SwitchOn = mkV2 (mkV "on" (mkV "switch")) ;
+ SwitchOff = mkV2 (mkV "off" (mkV "switch")) ;
+ Dim = mkV2 (mkV "dim") ;
+
+ switchable_Light = <> ;
+ switchable_Fan = <> ;
+ dimmable_Light = <> ;
+
+}
diff --git a/book/examples/chapter6/DShopping.gf b/book/examples/chapter6/DShopping.gf
new file mode 100644
index 000000000..a5a06e070
--- /dev/null
+++ b/book/examples/chapter6/DShopping.gf
@@ -0,0 +1,24 @@
+abstract DShopping = {
+ flags startcat = Comment ;
+ cat
+ Comment ;
+ Dom ;
+ Item Dom ;
+ Kind Dom ;
+ Quality Dom ;
+ fun
+ DFood, DCloth : Dom ;
+
+ Pred : (d : Dom) -> Item d -> Quality d -> Comment ;
+ This, That : (d : Dom) -> Kind d -> Item d ;
+ Mod : (d : Dom) -> Quality d -> Kind d -> Kind d ;
+ Wine, Cheese, Fish : Kind DFood ;
+ Very : (d : Dom) -> Quality d -> Quality d ;
+ Fresh, Warm, Delicious, Boring : Quality DFood ;
+
+ Shirt, Jacket : Kind DCloth ;
+ Comfortable : Quality DCloth ;
+
+ Italian, Expensive, Elegant : (d : Dom) -> Quality d ;
+
+}
diff --git a/book/examples/chapter6/DShoppingEng.gf b/book/examples/chapter6/DShoppingEng.gf
new file mode 100644
index 000000000..3dc3a2cc2
--- /dev/null
+++ b/book/examples/chapter6/DShoppingEng.gf
@@ -0,0 +1,33 @@
+--# -path=.:present
+
+concrete DShoppingEng of DShopping = open SyntaxEng, ParadigmsEng in {
+
+ lincat
+ Comment = Cl ;
+ Item = NP ;
+ Kind = CN ;
+ Quality = AP ;
+ lin
+ Pred _ item quality = mkCl item quality ;
+ This _ kind = mkNP this_QuantSg kind ;
+ That _ kind = mkNP that_QuantSg kind ;
+ Mod _ quality kind = mkCN quality kind ;
+ Very _ quality = mkAP very_AdA quality ;
+
+ Shirt = mkCN (mkN "shirt") ;
+ Jacket = mkCN (mkN "jacket") ;
+ Wine = mkCN (mkN "wine") ;
+ Cheese = mkCN (mkN "cheese") ;
+ Fish = mkCN (mkN "fish" "fish") ;
+ Fresh = mkAP (mkA "fresh") ;
+ Warm = mkAP (mkA "warm") ;
+ Italian _ = mkAP (mkA "Italian") ;
+ Expensive _ = mkAP (mkA "expensive") ;
+ Elegant _ = mkAP (mkA "elegant") ;
+ Delicious = mkAP (mkA "delicious") ;
+ Boring = mkAP (mkA "boring") ;
+ Comfortable = mkAP (mkA "comfortable") ;
+
+ DFood, DCloth = {s = []} ;
+
+}
diff --git a/book/examples/chapter6/Nat.gf b/book/examples/chapter6/Nat.gf
new file mode 100644
index 000000000..ba0dfe4a1
--- /dev/null
+++ b/book/examples/chapter6/Nat.gf
@@ -0,0 +1,22 @@
+abstract Nat = {
+ 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
+
+ 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/Verbs.gf b/book/examples/chapter6/Verbs.gf
new file mode 100644
index 000000000..371450aeb
--- /dev/null
+++ b/book/examples/chapter6/Verbs.gf
@@ -0,0 +1,22 @@
+abstract Verbs = {
+
+cat
+ S ; NP ; Subcat ; V Subcat ; Args Subcat ;
+
+fun
+ cIntr : Subcat ;
+ cTr : Subcat ;
+ cS : Subcat ;
+
+ aIntr : NP -> Args cIntr ;
+ aTr : NP -> NP -> Args cTr ;
+ aS : NP -> S -> Args cS ;
+
+ pred : (s : Subcat) -> V s -> Args s -> S ;
+
+ john, mary : NP ;
+ walk : V cIntr ;
+ love : V cTr ;
+ know : V cS ;
+
+} \ No newline at end of file
diff --git a/book/examples/chapter6/VerbsEng.gf b/book/examples/chapter6/VerbsEng.gf
new file mode 100644
index 000000000..b235178d9
--- /dev/null
+++ b/book/examples/chapter6/VerbsEng.gf
@@ -0,0 +1,22 @@
+concrete VerbsEng of Verbs = {
+
+lincat
+ S, NP, Subcat, V = Str ; Args = Str * Str ;
+
+lin
+ cIntr = [] ;
+ cTr = [] ;
+ cS = [] ;
+
+ aIntr su = <su,[]> ;
+ aTr su ob = <su,ob> ;
+ aS su s = <su,"that" ++ s> ;
+
+ pred _ v xs = xs.p1 ++ v ++ xs.p2 ;
+
+ john = "John" ; mary = "Mary" ;
+ walk = "walks" ;
+ love = "loves" ;
+ know = "knows" ;
+
+}