Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
* Functional programming using caml light
@ 2006-11-01 12:12 ciol
  2006-11-01 12:42 ` ciol
  0 siblings, 1 reply; 3+ messages in thread
From: ciol @ 2006-11-01 12:12 UTC (permalink / raw)
  To: caml-list

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 ?)


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2006-11-02 20:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-01 12:12 Functional programming using caml light ciol
2006-11-01 12:42 ` ciol
2006-11-02 20:58   ` ciol

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox