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 LAA23504; Mon, 29 Oct 2001 11:38:05 +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 LAA23391 for ; Mon, 29 Oct 2001 11:38:04 +0100 (MET) Received: from beaune.inria.fr (beaune.inria.fr [128.93.8.3]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f9TAc4n15955 for ; Mon, 29 Oct 2001 11:38:04 +0100 (MET) Received: by beaune.inria.fr (8.8.8/1.1.22.3/14Sep99-0328PM) id LAA0000013411; Mon, 29 Oct 2001 11:37:58 +0100 (MET) From: Luc Maranget Message-Id: <200110291037.LAA0000013411@beaune.inria.fr> Subject: Re: [Caml-list] "Or" patterns when both matchings To: pixel@mandrakesoft.com (Pixel) Date: Mon, 29 Oct 2001 11:37:58 +0100 (MET) Cc: caml-list@pauillac.inria.fr In-Reply-To: from "Pixel" at oct 28, 2001 12:02:02 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > > > 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. > > is there a reason for not using the classical pattern matching rule, to make > the ordering matters? (i've been nastily beat by this :-/) > > eg: > > > type foo = Bar | Foo of foo > > let f1 = function > | Foo(a) > | a -> a > > let f2 = function > | Foo(a) -> a > | a -> a > > let e1 = f1 (Foo Bar) (*=> Foo Bar *) > let e2 = f2 (Foo Bar) (*=> Bar *) > > > 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