summaryrefslogtreecommitdiff
path: root/examples/jem-math/MathIta1.gf
diff options
context:
space:
mode:
authoraarne <aarne@cs.chalmers.se>2008-09-15 15:28:47 +0000
committeraarne <aarne@cs.chalmers.se>2008-09-15 15:28:47 +0000
commite112fd188f905d90b727101fdbfa21478f4c9d18 (patch)
treed149a7c013a3720d49cfaa028cc317b8f0ce186f /examples/jem-math/MathIta1.gf
parent117b38e47ff2c98402b975ada3240b5d4e996d86 (diff)
JEM tutorial examples - some files missing still
Diffstat (limited to 'examples/jem-math/MathIta1.gf')
-rw-r--r--examples/jem-math/MathIta1.gf112
1 files changed, 112 insertions, 0 deletions
diff --git a/examples/jem-math/MathIta1.gf b/examples/jem-math/MathIta1.gf
new file mode 100644
index 000000000..6606ce197
--- /dev/null
+++ b/examples/jem-math/MathIta1.gf
@@ -0,0 +1,112 @@
+concrete MathIta1 of Math = {
+
+param
+ Gender = Masc | Fem ;
+ Case = Nom | Gen | Dat ;
+
+lincat
+ Prop = Str ;
+ Exp = NounPhrase ;
+
+oper
+ NounPhrase : Type = {s : Case => Str ; g : Gender} ;
+
+ exp : (n,g,d : Str) -> Gender -> NounPhrase =
+ \n,g,d,ge -> {
+ s = table {
+ Nom => n ;
+ Gen => g ;
+ Dat => d
+ } ;
+ g = ge
+ } ;
+
+ const : Str -> Gender -> NounPhrase = \s,g ->
+ exp s ("di" ++ s) ("a" ++ s) g ;
+
+ funct1 : Str -> Gender -> NounPhrase -> NounPhrase = \f,g,x -> {
+ s = \\c => defArt g c ++ f ++ x.s ! Gen ;
+ g = g
+ } ;
+
+ funct2 : Str -> Gender -> NounPhrase -> NounPhrase -> NounPhrase = \f,g,x,y -> {
+ s = \\c => defArt g c ++ f ++ x.s ! Gen ++ y.s ! Gen ;
+ g = g
+ } ;
+
+ defArt : Gender -> Case -> Str = \g,c -> case <g,c> of {
+ <Masc,Nom> => "il" ;
+ <Masc,Gen> => "del" ;
+ <Masc,Dat> => "al" ;
+ <Fem, Nom> => "la" ;
+ <Fem, Gen> => "della" ;
+ <Fem, Dat> => "alla"
+ } ;
+
+ Adjective : Type = Gender -> Str ;
+
+ pred1 : Str -> NounPhrase -> Str = \a,x ->
+ x.s ! Nom ++ "è" ++ adj a x.g ;
+
+ pred2 : Str -> Str -> Case -> NounPhrase -> NounPhrase -> Str = \a,s,c,x,y ->
+ x.s ! Nom ++ "è" ++ adj a x.g ++ s ++ y.s ! c ;
+
+ adj : Str -> Adjective = \s,g -> case g of {
+ Masc => s ;
+ Fem => case s of {
+ ner + "o" => ner + "a" ;
+ _ => s
+ }
+ } ;
+
+lin
+ And a b = a ++ "e" ++ b ;
+ Or a b = a ++ "o" ++ b ;
+ If a b = "si" ++ a ++ "allora" ++ b ;
+
+ Zero = const "zero" Masc ;
+
+ Successor = funct1 "successore" Masc ;
+
+ Sum = funct2 "somma" Fem ;
+ Product = funct2 "prodotto" Masc ;
+
+ Even = pred1 "pari" ;
+ Odd = pred1 "dispari" ;
+ Prime = pred1 "primo" ;
+
+ Equal = pred2 "uguale" [] Dat ;
+ Less = pred2 "inferiore" [] Dat ;
+ Greater = pred2 "superiore" [] Dat ;
+ Divisible = pred2 "divisibile" "per" Nom ;
+
+lincat
+ Var = Str ;
+lin
+ X = "x" ;
+ Y = "y" ;
+
+ EVar x = const x Masc ;
+ EInt i = const i.s Masc ;
+
+ ANumberVar x = const ("un numero" ++ x) Masc ;
+ TheNumberVar x = {
+ s = \\c => defArt Masc c ++ "numero" ++ x ;
+ g = Masc
+ } ;
+
+
+-- overloaded API
+oper
+ funct = overload {
+ funct : Str -> Gender -> NounPhrase = const ;
+ funct : Str -> Gender -> NounPhrase -> NounPhrase = funct1 ;
+ funct : Str -> Gender -> NounPhrase -> NounPhrase -> NounPhrase = funct2
+ } ;
+
+ pred = overload {
+ pred : Str -> NounPhrase -> Str = pred1 ;
+ pred : Str -> Str -> Case -> NounPhrase -> NounPhrase -> Str = pred2
+ } ;
+
+}