summaryrefslogtreecommitdiff
path: root/examples/jem-math/MathIta1.gf
blob: 6606ce197e7768e97d46740c02baeb7d08fff546 (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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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
    } ;

}