diff --git a/book/examples/chapter2/Food.probs b/book/examples/chapter2/Food.probs new file mode 100644 index 000000000..2d75774a1 --- /dev/null +++ b/book/examples/chapter2/Food.probs @@ -0,0 +1,4 @@ + This 0.8 + Mod 0.2 + Wine 0.0 + Fresh 0.4 diff --git a/book/examples/chapter4/Exx.gf b/book/examples/chapter4/DefArtGer.gf similarity index 94% rename from book/examples/chapter4/Exx.gf rename to book/examples/chapter4/DefArtGer.gf index e7df70595..1ef9394eb 100644 --- a/book/examples/chapter4/Exx.gf +++ b/book/examples/chapter4/DefArtGer.gf @@ -1,4 +1,4 @@ -resource Exx = { +resource DefArtGer = { param DetForm = DSg Gender Case | DPl Case ; param Gender = Masc | Fem | Neutr ; diff --git a/book/examples/chapter5/FoodsEng.gf b/book/examples/chapter5/FoodsEng.gf index 5c2158ce2..e1bc40c7a 100644 --- a/book/examples/chapter5/FoodsEng.gf +++ b/book/examples/chapter5/FoodsEng.gf @@ -1,18 +1,19 @@ ---# -path=.:../foods:minimal:present +--# -path=.:present -concrete FoodsEng of Foods = open SyntaxEng,ParadigmsEng in { +concrete FoodsEng of Foods = + open SyntaxEng,ParadigmsEng in { lincat - Phrase = Cl ; + Comment = Utt ; Item = NP ; Kind = CN ; Quality = AP ; lin - Is item quality = mkCl item quality ; + Pred item quality = mkUtt (mkCl item quality) ; This kind = mkNP this_Quant kind ; That kind = mkNP that_Quant kind ; These kind = mkNP this_Quant plNum kind ; Those kind = mkNP that_Quant plNum kind ; - QKind quality kind = mkCN quality kind ; + Mod quality kind = mkCN quality kind ; Wine = mkCN (mkN "wine") ; Pizza = mkCN (mkN "pizza") ; Cheese = mkCN (mkN "cheese") ; 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 ; + +} diff --git a/book/examples/chapter7/Map.gf b/book/examples/chapter7/Map.gf new file mode 100644 index 000000000..52deebb87 --- /dev/null +++ b/book/examples/chapter7/Map.gf @@ -0,0 +1,10 @@ +abstract Map = { +flags startcat = Query ; +cat + Query ; Input ; Place ; Click ; +fun + GoFromTo : Place -> Place -> Input ; + ThisPlace : Click -> Place ; + QueryInput : Input -> Query ; + ClickCoord : Int -> Int -> Click ; +} diff --git a/book/examples/chapter7/MapEng.gf b/book/examples/chapter7/MapEng.gf new file mode 100644 index 000000000..fee0b502c --- /dev/null +++ b/book/examples/chapter7/MapEng.gf @@ -0,0 +1,17 @@ +concrete MapEng of Map = { +lincat + Query = {s : Str} ; + Input, Place = {s : Str ; p : Str} ; + Click = {p : Str} ; +lin + GoFromTo x y = { + s = "I want to go from" ++ x.s ++ "to" ++ y.s ; + p = x.p ++ y.p + } ; + ThisPlace c = { + s = "this place" ; + p = c.p + } ; + QueryInput i = {s = i.s ++ ";" ++ i.p} ; + ClickCoord x y = {p = "(" ++ x.s ++ "," ++ y.s ++ ")"} ; +} diff --git a/book/examples/chapter8/GeometryEng.gf b/book/examples/chapter8/GeometryEng.gf index 36d840303..e2e22776e 100644 --- a/book/examples/chapter8/GeometryEng.gf +++ b/book/examples/chapter8/GeometryEng.gf @@ -1,4 +1,4 @@ ---# -path=alltenses +--# -path=.:present concrete GeometryEng of Geometry = LogicEng ** open SyntaxEng, ParadigmsEng in { diff --git a/book/examples/chapter8/Graftal.gf b/book/examples/chapter8/Graftal.gf new file mode 100644 index 000000000..e85b9b2f7 --- /dev/null +++ b/book/examples/chapter8/Graftal.gf @@ -0,0 +1,7 @@ +-- (c) Krasimir Angelov 2009 +abstract Graftal = { + cat N; S; + fun z : N ; + s : N -> N ; + c : N -> S ; + } diff --git a/book/examples/chapter8/Sierpinski.gf b/book/examples/chapter8/Sierpinski.gf new file mode 100644 index 000000000..722088ce5 --- /dev/null +++ b/book/examples/chapter8/Sierpinski.gf @@ -0,0 +1,16 @@ +concrete Sierpinski of Graftal = { + lincat N = {a : Str; b : Str} ; + lincat S = {s : Str} ; + + lin z = {a = A; b = B} ; + lin s x = { + a = x.b ++ R ++ x.a ++ R ++ x.b ; + b = x.a ++ L ++ x.b ++ L ++ x.a + } ; + lin c x = {s = "newpath 300 550 moveto" ++ x.a ++ "stroke showpage"} ; + + oper A : Str = "0 2 rlineto" ; + oper B : Str = "0 2 rlineto" ; + oper L : Str = "+60 rotate" ; + oper R : Str = "-60 rotate" ; +}