[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | ciol <ciol13@g...> |
| Subject: | Functional programming using caml light |
Hello,
in this book ( http://caml.inria.fr/pub/docs/fpcl/index.html ), there is
the following grammar (chapter 10.3, on streams etc...) :
Expr ::= Mult
| Mult + Expr
| Mult - Expr
[...]
after factoring common prefixes, the author obtains :
Expr ::= Mult RestExpr
RestExpr ::= + Mult RestExpr
|- Mult RestEXpr
|(* nothing *)
[...]
But I don't obtain the same result for RestExpr :
RestExpr ::= + Mult Expr
|- Mult Expr
| (* nothing *)
Am I wrong ? (and why ?)
----------------------------------
Another question (totally different) :
I've created the type :
type expr = Plus of expr * expr
| Minus of expr * expr
| Div of expr * expr
| Sin of expr
| Cos of expr
[etc... (not important)]
when I match an expression, I do for instance :
Plus (u, v) -> blablabla (u, v)
Minus (u, v) -> blablabla (u, v) (same result as above)
Div (u, v) -> a different result
Can I reduce the code in order to do such a thing :
Div (u, v) -> blabliblou
BinaryFunction (u, v) -> blablabla (u, v)
(BinaryFunction match for both Plus and Minus (all the others binary
functions))
Thank you (maybe should I have written in french ?)