Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
curried fns
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jocelyn Serot <Jocelyn.Serot@l...>
Subject: curried fns


Could someone please explain the difference(s) between:

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


	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 *)

S-mail: LASMEA - URA 1793 CNRS, Universite Blaise Pascal, 63177 Aubiere cedex
Tel: (33) - Fax: (33)