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 LAA18988 for caml-redistribution; Tue, 21 Nov 1995 11:50:39 +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 UAA14757 for ; Mon, 20 Nov 1995 20:50:54 +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 UAA18979 for ; Mon, 20 Nov 1995 20:50:43 +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 UAA12074 for ; Mon, 20 Nov 1995 20:50:41 +0100 Received: from logatome.micronet.fr (root@logatome.micronet.fr [194.51.75.1]) by concorde.inria.fr (8.7.1/8.6.9) with ESMTP id UAA18974 for ; Mon, 20 Nov 1995 20:50:33 +0100 (MET) Received: from [194.51.75.132] (ppp00.micronet.fr [194.51.75.132]) by logatome.micronet.fr (8.6.9/8.6.9) with SMTP id UAA29149 for ; Mon, 20 Nov 1995 20:50:24 +0100 Message-Id: Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Date: Mon, 20 Nov 1995 20:51:56 +0200 To: caml-list@margaux.inria.fr From: cheno@micronet.fr (Laurent CHENO) Subject: Re: curried fns Sender: weis Jocelyn Serot wrote : >>Hello, >> >>Could someone please explain the difference(s) between: >> >> let f x =3D function y -> y + x;; >> >>and >> >> let f x y =3D y + x;; >> >>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 =3D let z =3D 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 =3D let z =3D fact x in y + z;; >> map (h 30) [1;2;3];; >> >>causes fact 30 to be evaluated _for each_ element of the list. >> >>Is this normal or do i misunderstand sth about curryfied fns ?.. >> >>Thanks for any help 1. excuse my poor english, thank's 2. I think this can help (I hope so !) =46or my example : #let fact x =3D print_int x ; print_newline() ; x ;; fact : int -> int =3D first version #let h1 x =3D let z =3D fact x in function y -> y + z ;; h1 : int -> int -> int =3D NB : the result of h1 30 is a function, which has been evaluated in a environment where z yields for the result of fact 30 So, we can see the result of print_int in *this* call ! #let a1 =3D h1 30 ;; 30 a1 : int -> int =3D Now, a1 is all defined : no more print ... the function a1 don't print anyth= ing #map a1 [1 ; 2 ; 3] ;; - : int list =3D [31; 32; 33] second version #let h2 x y =3D let z =3D fact x in y + z ;; h2 : int -> int -> int =3D there is no call for fact : you have specialized the first (and not last) argument of h2 #let a2 =3D h2 30 ;; a2 : int -> int =3D now the evaluation is complete, and there is calls for print_int #map a2 [1 ; 2 ; 3] ;; 30 30 30 - : int list =3D [31; 32; 33] # Laurent Ch=E9no ------------------------------------------------------------------- Laurent CHENO teaching at / enseignant au Lyc=E9e Louis-le-Grand - 123 rue Saint-Jacques 75231 PARIS CEDEX 05 - FRANCE personal phone (33) 1 48 05 16 04 - fax (33) 1 48 07 80 18 -------------------------------------------------------------------