curried fns

Jocelyn Serot (Jocelyn.Serot@lasmea.univ-bpclermont.fr)
Mon, 20 Nov 1995 16:54:06 MET

Message-Id: <199511201556.QAA15838@concorde.inria.fr>
From: Jocelyn Serot <Jocelyn.Serot@lasmea.univ-bpclermont.fr>
Subject: curried fns
To: caml-list@margaux.inria.fr
Date: Mon, 20 Nov 1995 16:54:06 MET

Hello,

Could someone please explain the difference(s) between:

let f x = function y -> y + x;;

and

let f x y = 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 = 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 ?..

Thanks for any help

Jocelyn S.

(* note 1: this example is inspired from a a similar one given by
X. Leroy in his Research Report INRIA/117 about the Zinc experiment *)

--
E-mail: Jocelyn.Serot@lasmea.univ-bpclermont.fr
S-mail: LASMEA - URA 1793 CNRS, Universite Blaise Pascal, 63177 Aubiere cedex
Tel: (33) 73.40.73.30 - Fax: (33) 73.40.72.62