Version française
Home     About     Download     Resources     Contact us    
Browse thread
RE: [Caml-list] currying...
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Adam Granicz <granicz@c...>
Subject: RE: [Caml-list] currying...
it does evaluate it partially. you have to remember that functions are
first-class values as well. as a matter of fact, the formally declared
parameters do not really matter, they are resolved by the compiler by
looking at the body of the function. declaring formal parameters is only
necessary when the order of these parameters can not be unambigously
determined. thus

let neg = function
	true -> false
   |  false -> true

is automatically understood as val: neg: bool -> bool.

also, remember that ocaml functions take only one parameter, so

val f: int -> int -> int -> unit

is actually the composition of several functions, the first taking an int
and returning a unit, the second taking an int and returning an int, and so
on.

> so f actually takes two ints, prints them, and then returns a
> function that takes an int and returns unit.  From the val

this one would be

val f: int -> int -> (int -> unit)

anyway, as to your question: if enough arguments are supplied so that the
function can be evaluated, then it is called and returns whatever that
function was supposed to return. however, if not all arguments were given
then the function is only partially evaluated with all known parameters.

let f i j = i+j

f 1 returns a function that expects one argument, so

let g = f 1

and

g 2 return 3.

hope this helps..

adam.

-------------------
To unsubscribe, mail caml-list-request@inria.fr.  Archives: http://caml.inria.fr