Advanced Functional Prog.
back - up - next
Algebraic Datatypes
- Grammar as Datatypes
The "information" contained in the expression "e=1+(2*3)" can be formalized by the following type definition:
type Exp = Val of int | Plus of Exp*Exp | Mult of Exp*Exp;;
let e = Plus (Val 1,Mult (Val 2, Val 3));;
- "Interpretation" is then a particular function:
let rec interp e =
match e with
| Val v -> v
| Plus (e1,e2) -> (interp e1)+(interp e2)
| Mult (e1,e2) -> (interp e1)*(interp e2);;
interp e;;
10
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp
advanced functional programming programmation fonctionnelle avancée dr mulhouse ensisa france thiry laurent uha fun fsharp