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 LAA04945; Tue, 6 Mar 2001 11:22:20 +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 LAA04559 for ; Tue, 6 Mar 2001 11:22:19 +0100 (MET) Received: from terre.irisa.fr (terre.irisa.fr [131.254.60.118]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f26AMID16482 for ; Tue, 6 Mar 2001 11:22:19 +0100 (MET) Received: from irisa.fr (heurtebise.irisa.fr [131.254.50.61]) by terre.irisa.fr (8.9.3/8.9.3) with ESMTP id LAA12366; Tue, 6 Mar 2001 11:22:15 +0100 (MET) Message-ID: <3AA4BA57.4F9DBA12@irisa.fr> Date: Tue, 06 Mar 2001 11:22:15 +0100 From: Thomas Colcombet Organization: IRISA, Campus de Beaulieu, 35042 Rennes Cedex, FRANCE X-Mailer: Mozilla 4.76 [en] (X11; U; SunOS 5.7 sun4u) X-Accept-Language: fr, en MIME-Version: 1.0 To: Chris Hecker CC: caml-list@inria.fr Subject: Re: [Caml-list] currying... References: <4.3.2.7.2.20010306012957.00c7cf00@shell16.ba.best.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk As I understand the problem, may be the small following examples explain how CAML implements curryfication : # let f = fun x -> (Printf.printf "%d\n" x; fun y -> Printf.printf "%d\n" y);; val f : int -> int -> unit = # f 1;; 1 - : int -> unit = # f 1 2;; 1 2 - : unit = () This function does not behave as the following one : # let f = fun x y -> (Printf.printf "%d\n" x; Printf.printf "%d\n" y);; val f : int -> int -> unit = # f 1;; - : int -> unit = # f 1 2;; 1 2 - : unit = () In other words, a fun construct is evaluated only when all its argument are known. The notation "let f x y = ..." is just syntactic sugar for "let f = fun x y -> ...". Thomas Colcombet > How does caml know when to call a function? For example, say I have: > > val f: int -> int -> int -> unit > > and the definition of f is > > let f x y = Printf.printf "%d %d" x y;Printf.printf "%d" > > so f actually takes two ints, prints them, and then returns a function that takes an int and returns unit. From the val declaration above in a .cmi file, how can caml tell the difference between that f and this one: > > let f x y z = Printf.printf "%d %d %d" x y z > > How does it know "when" to call f, since you need a different number of parameters for the different definitions? The top f prints x y when it's called with two parms, so it doesn't wait until all three parms have been passed. > > I have a feeling I'm missing something fundamental here, or else the definition of a function internally has a field for its arity and it just partially applies until it reaches the total arity. I thought I remembered seeing some documentation on this months ago, but I can't find it now... > > It doesn't seem to partially evaluate the function or anything insane like that. > > Chris > > ------------------- > 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