From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id LAA15421 for caml-redistribution@pauillac.inria.fr; Fri, 17 Mar 2000 11:29:08 +0100 (MET) Resent-Message-Id: <200003171029.LAA15421@pauillac.inria.fr> Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id KAA08063; Fri, 17 Mar 2000 10:42:15 +0100 (MET) Message-ID: <20000317104215.56763@pauillac.inria.fr> Date: Fri, 17 Mar 2000 10:42:15 +0100 From: Pierre Weis To: Julian Assange Cc: caml-list@pauillac.inria.fr Subject: Re: let ... in layout References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 0.89.1 In-Reply-To: ; from Julian Assange on Thu, Mar 16, 2000 at 09:18:04AM +1100 Resent-From: weis@pauillac.inria.fr Resent-Date: Fri, 17 Mar 2000 11:29:08 +0100 Resent-To: caml-redistribution@pauillac.inria.fr > Jean-Yves Moyen writes: > > > let f a b c= > > match a,b,c with > > ... > > > > which allows you to match several arguments at once. > > Sure, but > > let f a b c = > match a,b,c with > 0,1,2 -> 3 > > is a lot more cluttered than > > f 0 1 2 = 3 > > This wouldn't really be an issue except that pattern matching is so > common. Intuitive brevity (as opposed to the brevity represented by > languages such as perl) is what makes both haskell and *ml so > readable. While both functions seem equally readable because they are > both small, once you have a screen full of them there is a significant > difference in clarity. > > Cheers, > Julian. You're right but this is not only a problem of syntax. There are semantics issues to consider. As for the syntax, your example is a bit contrieved, since there are not that many functions with pattern matching on 3 arguments that has only one match case. In general, such a complex function will have many cases and then the (admittedly heavier) way of writing the code in Caml gives you an extra benefit of naming the arguments, not repeating the function name, and clearly exhibit the complete pattern matching in one place: let f a b c = match a, b, c with | 0, _, 0 -> a + b + c | .... Also, the semantics of partial applications of curried pattern matching is not clear: consider your f example let f 0 1 2 = 3;; What's the meaning of this definition ? Two interpretations have been used in Caml: let f1 a b c = match a, b, c with | 0, 1, 2 -> 3 | _ -> raise Match_failure let f2 = function | 0 -> (function | 1 -> (function | 2 -> 3 | _ -> raise Match_failure) | _ -> raise Match_Failure) | _ -> raise Match_Failure I guess f2 is more consistent with the usual semantics of ML, while f1 seems to be more natural for users: with f2 partial applications will fail as early as necessary: (f 1 raises Match_failure as the definition of g in let g = List.map (f 1)), while with f1, application of f will fail only when 3 arguments are provided. I guess that this is this semantic problem, and the new syntax to add that prevents the addition of this feature to Caml. Best regards, Pierre Weis INRIA, Projet Cristal, http://pauillac.inria.fr/~weis