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 LAA18998 for caml-redistribution; Tue, 21 Nov 1995 11:51:00 +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 GAA16293 for ; Tue, 21 Nov 1995 06:20:44 +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 GAA22507 for ; Tue, 21 Nov 1995 06:20:45 +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 GAA13490 for ; Tue, 21 Nov 1995 06:20:43 +0100 Received: from world-net.sct.fr (world-net.sct.fr [194.2.128.2]) by concorde.inria.fr (8.7.1/8.6.9) with SMTP id GAA22503 for ; Tue, 21 Nov 1995 06:20:43 +0100 (MET) Received: from client104.sct.fr (client104.sct.fr [194.2.128.134]) by world-net.sct.fr (8.6.12/8.6.10) with SMTP id GAA03663 for ; Tue, 21 Nov 1995 06:17:13 +0100 Date: Tue, 21 Nov 1995 06:17:13 +0100 Message-Id: <199511210517.GAA03663@world-net.sct.fr> X-Sender: tarizzo@world-net.sct.fr X-Mailer: Windows Eudora Version 1.4.4 Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" To: caml-list@margaux.inria.fr From: tarizzo@world-net.sct.fr (Tarizzo Martial) Subject: Re: curried fns Sender: weis >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. > >Is this normal or do i misunderstand sth about curryfied fns ?.. I think it's perfectly normal. One can rewrite the two definitions of h without the syntactic sugar provided by 'in' : * for the first one : let h = fun x -> (fun z -> (fun y -> y+z)) (fact x);; * for the second one : let h = fun x -> fun y -> (fun z -> y+z) (fact x);; It's clear that the value returned by h x;; is a function of y. In the first def, fact x is evaluated when we compute h x;; and this value is 'captured' in the definition of fun y In the second def, fact x is computed in the body of the function of y, i.e each time this funciotn is called. It's very easy to see this behavior : try to evaluate h 30;; with a side effect in the fact function (print its argument for example) The first definition gives : let h x = let z = fact x in fun y -> y + z;; h : int -> int -> int = #h 3;; 3 - : int -> int = while the second one gives : let h x y = let z = fact x in y + z;; h : int -> int -> int = #h 3;; - : int -> int = ********************************* Tarizzo Martial Prof. Sc Physiques Classes preparatoires Lycee J MOULIN 57600 FORBACH Email: tarizzo@world-net.sct.fr 74014.3307@compuserve.com Compuserve : 74014,3307 *********************************