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
Re: [Caml-list] Error: This function is applied to too many arguments,maybe you forgot a `; '
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2008-08-04 (05:58)
From: Yves Bertot <Yves.Bertot@s...>
Subject: Re: [Caml-list] Error: This function is applied to too many arguments,maybe you forgot a `; '

To be more precise, Ocaml being a functional language, any function, 
when applied
to one argument, may return a new function which can in turn be applied 
to another

Thus if you write :

(a (b)) (c),

Ocaml (and most other functional programming languages), understand that

a(b) is supposed to be a function, that returns another function, then 
applied to c.

In practice, this trick is used extensively throughout functional 
programs, so
that placing parentheses around arguments would result in a humongous number
of parentheses.  For this reason, a new convention for parentheses was 
you don't put any parentheses around function arguments, unless it is 
for disambiguation (for instance, if you want b to be applied to c, and 
you don't
place parentheses around the function part, so that (a(b))(c) is simply 

a b c

This means : a applied to b, and then to c,

Now, if you want "a applied to the result of applying b to c", you write

a (b c)

Please note there are no parentheses around c.

In practice, most functions taking several arguments are described in this
manner, instead of being described as function taking a pair as argument.
This is known as "currification" because Curry was one of the early 
to advocate the idea that mathematics (and programming) could be described
with only one-argument functions.

In your case, both print_int and fac are one argument functions, as can 
be seen from
their type.