caml-list - the Caml user's mailing list
 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

* Re: Functional programming using caml light
  2006-11-01 12:12 Functional programming using caml light ciol
@ 2006-11-01 12:42 ` ciol
  2006-11-02 20:58   ` ciol
  0 siblings, 1 reply; 3+ messages in thread
From: ciol @ 2006-11-01 12:42 UTC (permalink / raw)
  To: caml-list

ciol wrote:

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

_Sorry_, it's an error, I obtain :
RestExpr ::= + Expr
            | - Expr
            | (* nothing *)

But I've just realized that the author's solution is in fact the same as 
mine (he replaced Expr in RestExpr by Mult RestExpr. But why ? Isn't it 
more complicated ? The result in caml will be identical  wont it be ?



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

* Re: Functional programming using caml light
  2006-11-01 12:42 ` ciol
@ 2006-11-02 20:58   ` ciol
  0 siblings, 0 replies; 3+ messages in thread
From: ciol @ 2006-11-02 20:58 UTC (permalink / raw)
  To: caml-list

c'est bon j'ai trouvé, ma grammaire ne gère pas l'associativité à gauche  :
sur cet exemple "1 - 3 + 5", je vais l'analyser comme Moins (1, Plus (3, 
5)), alors que c'est évidemment Plus (Moins (1, 3), 5)

désolé.



^ 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;
as well as URLs for NNTP newsgroup(s).