From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.6 required=5.0 tests=RCVD_NUMERIC_HELO,SPF_FAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 299FDBC69 for ; Wed, 1 Nov 2006 13:20:31 +0100 (CET) Received: from ciao.gmane.org (main.gmane.org [80.91.229.2]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id kA1CKUhO002083 (version=TLSv1/SSLv3 cipher=AES256-SHA bits=256 verify=NO) for ; Wed, 1 Nov 2006 13:20:30 +0100 Received: from root by ciao.gmane.org with local (Exim 4.43) id 1GfF4c-00062K-RG for caml-list@inria.fr; Wed, 01 Nov 2006 13:20:03 +0100 Received: from 88.122.97.102 ([88.122.97.102]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 01 Nov 2006 13:20:02 +0100 Received: from ciol13 by 88.122.97.102 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Wed, 01 Nov 2006 13:20:02 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: ciol Subject: Functional programming using caml light Date: Wed, 01 Nov 2006 13:12:12 +0100 Message-ID: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@sea.gmane.org X-Gmane-NNTP-Posting-Host: 88.122.97.102 User-Agent: Thunderbird 1.5.0.7 (X11/20060927) Sender: news X-j-chkmail-Score: MSGID : 4548910E.000 on discorde : j-chkmail score : X : 0/20 1 X-Miltered: at discorde with ID 4548910E.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; expr:01 mult:01 mult:01 expr:01 blablabla:01 blablabla:01 obtains:98 grammar:01 functions:01 expression:01 binary:01 prefixes:02 caml:02 caml:02 match:02 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 ?)