From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA26466; Tue, 30 Oct 2001 19:42:28 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA27053 for ; Tue, 30 Oct 2001 19:42:27 +0100 (MET) Received: from mail4.microsoft.com (mail4.microsoft.com [131.107.3.122]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f9UIgQb13896 for ; Tue, 30 Oct 2001 19:42:26 +0100 (MET) Received: from inet-vrs-04.redmond.corp.microsoft.com ([157.54.8.154]) by mail4.microsoft.com with Microsoft SMTPSVC(5.0.2195.2966); Tue, 30 Oct 2001 10:41:57 -0800 Received: from 157.54.8.109 by inet-vrs-04.redmond.corp.microsoft.com (InterScan E-Mail VirusWall NT); Tue, 30 Oct 2001 10:22:36 -0800 Received: from red-msg-04.redmond.corp.microsoft.com ([157.54.12.74]) by inet-hub-02.redmond.corp.microsoft.com with Microsoft SMTPSVC(5.0.2195.2966); Tue, 30 Oct 2001 10:22:28 -0800 X-MimeOLE: Produced By Microsoft Exchange V6.0.5762.0 Content-Class: urn:content-classes:message MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable Subject: RE: [Caml-list] "Or" patterns when both matchings Date: Tue, 30 Oct 2001 10:22:28 -0800 Message-ID: Thread-Topic: [Caml-list] "Or" patterns when both matchings Thread-Index: AcFgZv5trEtxS9CcR+yv+55HZfXXGgBCHKKg From: "Manuel Fahndrich" To: "Luc Maranget" , "Pixel" Cc: X-OriginalArrivalTime: 30 Oct 2001 18:22:28.0644 (UTC) FILETIME=[D5084E40:01C1616F] Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Hmm, I must side with Pixel here. Ease of compilation is rarely a good design principle for a programming language. The use of or patterns allows one to factor right hand sides as in the example shown below: | Foo(a) | a -> If Or-patterns do not follow the first-to-last matching order, then producing correct code and reading it becomes more difficult. I wasn't aware of the Or-compilation strategy and I'm sure I made this mistake in the past as well. -Maf -----Original Message----- From: Luc Maranget [mailto:luc.maranget@inria.fr]=20 Sent: Monday, October 29, 2001 2:38 AM To: Pixel Cc: caml-list@pauillac.inria.fr Subject: Re: [Caml-list] "Or" patterns when both matchings >=20 >=20 > from the documentation: > The pattern pattern1 | pattern2 represents the logical ``or'' of the two > patterns pattern1 and pattern2. [...] If both matchings succeed, it is > undefined which set of bindings is selected. >=20 > is there a reason for not using the classical pattern matching rule, to make > the ordering matters? (i've been nastily beat by this :-/) >=20 > eg: >=20 >=20 > type foo =3D Bar | Foo of foo >=20 > let f1 =3D function > | Foo(a)=20 > | a -> a >=20 > let f2 =3D function > | Foo(a) -> a > | a -> a >=20 > let e1 =3D f1 (Foo Bar) (*=3D> Foo Bar *) > let e2 =3D f2 (Foo Bar) (*=3D> Bar *) >=20 >=20 > thanks > -- > Pixel Yes there are two reasons 1. ease of compilation. As you have experienced yourself. In case one of the patterns in the or-pattern is a variable, then the or-pattern is reduced to a variable. Otherwise, compilation would be a bit more complicated. 2. Ideology. I consider that priority in or-patterns is something obscure, and would discourage relying on it. However the current (unspecified) semantics makes the idea of a ``partially useless'' matching clause a bit random, and this semantics may become more precise in the future. Cheers, --Luc ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr