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 OAA24636; Tue, 10 Apr 2001 14:19:01 +0200 (MET DST) 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 OAA24630 for ; Tue, 10 Apr 2001 14:19:00 +0200 (MET DST) Received: from mrwall.kal.com (mrwall.kal.com [194.193.14.236]) by nez-perce.inria.fr (8.11.1/8.10.0) with SMTP id f3ACIxn06487; Tue, 10 Apr 2001 14:18:59 +0200 (MET DST) Received: from mrwall.kal.com [194.193.14.236] (HELO localhost) by mrwall.kal.com (AltaVista Mail V2.0J/2.0J BL25J listener) id 0000_0045_3ad2_faf2_807e; Tue, 10 Apr 2001 13:22:10 +0100 MIME-Version: 1.0 Subject: RE: [Caml-list] variant with tuple arg in pattern match? Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable content-class: urn:content-classes:message X-MimeOLE: Produced By Microsoft Exchange V6.0.4417.0 Date: Tue, 10 Apr 2001 13:17:09 +0100 Message-ID: Thread-Topic: [Caml-list] variant with tuple arg in pattern match? Thread-Index: AcDAx4H0lqAx9KvlRmaNCqqxnwUx7gA7lWuw From: "Dave Berry" To: "Daniel de Rauglaudre" , Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk You certainly can avoid currying in functional languages. Currying is a hack that was created to keep the lambda calculus as simple as possible. Currying lets the lambda calculus simulate two things: 1. Multiple arguments. Fine for the calculus, but in any language with tuples or records we can just write f(x,y), like everybody else. 2. Partial application. Again, fine for the calculus, but for languages this fixes the decision of which arguments can be partially applied when the function is defined, instead of where it is used. If we define functions with tuple arguments, we can introduce an explicit syntax for partial application, e.g. f(_,y). The explicit syntax is particularly useful for ML, because of the value polymorphism rule. In pure functional languages (and SML'90), you can write: let flatten =3D fold \:: [] In ML, this gives an error (at least at top level), and you have to eta-expand the definition: let sum l =3D fold \:: [] l With explicit syntax for partial application, you would write: let sum =3D fold (\::, [], _) Daniel points out that you will always be able to return a function from a function. But currying is a partly syntactic hack; it relies on function application being notated by juxtaposition. Without this hack, you have to write: let f =3D g (x, y) f (z) instead of: g x y z In cases where a function is explicitly returning another (as opposed to just simulating multiple arguments), I think the explicit binding describes what is happening more clearly. Incidentally, using juxtaposition to denote application makes it harder for the parser to detect some errors. This makes it more likely that the user will see a type error where a simpler parse error would have been more appropriate. An earlier writer in this thread has already pointed out that if some arguments are mistakenly omitted in a curried application, this isn't reported until the point of use (and there might not even be any uses, if the function is only called for its side effects). -----Original Message----- From: Daniel de Rauglaudre [mailto:daniel.de_rauglaudre@inria.fr] Sent: Monday, April 09, 2001 8:34 To: caml-list@inria.fr Subject: Re: [Caml-list] variant with tuple arg in pattern match? Hi, On Mon, Apr 09, 2001 at 08:23:40AM +0200, Mattias Waldau wrote: > If so, I don't think that curried syntax is something good. I agree with your arguments, but... but you cannot avoid currification in functional languages. Ok, all your functions take non curried parameters, but how do you write a function which returns a function? If it is: let f x =3D fun y -> blahblah ok, you can write it: let f (x, y) =3D blahblah But, how do you transform it if it is: let f x =3D blahblahblah...; blah blah blah; fun y -> blah blah Currification is inside functional languages, you cannot decide to ignore it. And in OCaml, currified functions are more efficient (mmm... Xavier, tell us if I am wrong). Besides, if you don't apply all arguments, you get typing errors (in most cases), anyway. --=20 Daniel de RAUGLAUDRE daniel.de_rauglaudre@inria.fr http://cristal.inria.fr/~ddr/ ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr ------------------- To unsubscribe, mail caml-list-request@inria.fr. Archives: http://caml.inria.fr