From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.6.10/8.6.6) id LAA18991 for caml-redistribution; Tue, 21 Nov 1995 11:50:49 +0100 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.6.10/8.6.6) with ESMTP id VAA14885 for ; Mon, 20 Nov 1995 21:35:00 +0100 Received: from margaux.inria.fr (margaux.inria.fr [128.93.8.2]) by concorde.inria.fr (8.7.1/8.6.9) with ESMTP id VAA19338 for ; Mon, 20 Nov 1995 21:35:00 +0100 (MET) Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by margaux.inria.fr (8.6.10/8.6.6) with ESMTP id VAA12236 for ; Mon, 20 Nov 1995 21:34:59 +0100 Received: from melimelo.enst-bretagne.fr (melimelo.enst-bretagne.fr [192.108.115.36]) by concorde.inria.fr (8.7.1/8.6.9) with SMTP id VAA19334 for ; Mon, 20 Nov 1995 21:34:59 +0100 (MET) Received: by melimelo.enst-bretagne.fr (5.67b8/090294); Mon, 20 Nov 1995 21:32:33 +0100 Date: Mon, 20 Nov 1995 21:32:33 +0100 From: fauque@enst-bretagne.fr (Fauque UPS) Message-Id: <199511202032.AA39080@melimelo.enst-bretagne.fr> To: Jocelyn.Serot@lasmea.univ-bpclermont.fr, caml-list@margaux.inria.fr Subject: Re: curried fns Sender: weis I am not a caml expert and the gurus will say if I am wrong, but this is what I understand: > Could someone please explain the difference(s) between: > > let f x = function y -> y + x;; > > and > > let f x y = y + x;; there is absolutely no differences between these two expressions: y+x will be evaluated only when two arguments x and y are given to f. > Both have the same type (int -> int -> int) but they seem to behave > distinctly wrt evaluation strategy. > > For instance, if i use the 1st form and write: > > let h x = let z = fact x in fun y -> y + z;; > map (h 30) [1;2;3];; (* note 1 *) > > fact 30 gets evaluated only once (partial evaluation), while > the use of the 2nd form for the h function: > > let h x y = let z = fact x in y + z;; > map (h 30) [1;2;3];; > > causes fact 30 to be evaluated _for each_ element of the list. this is not the same case: the first form should have been: let h x = fun y -> let z = fact x in y + z;; and here fact 30 will be evaluated for each element of the list; you have done in fact an optimization by putting the fact x before the fun y -> and it lets caml compute the fact x without the need to know the actual value of y. Hubert Fauque hubert.fauque@enst-bretagne.fr