* Error: This function is applied to too many arguments, maybe you forgot a `;'
@ 2008-08-04 0:46 Ben Aurel
2008-08-05 12:11 ` [Caml-list] Error: This function is applied to too many arguments, maybe you forgot a `; ' Richard Jones
0 siblings, 1 reply; 5+ messages in thread
From: Ben Aurel @ 2008-08-04 0:46 UTC (permalink / raw)
To: caml-list
hi
I try to make my first steps with Ocaml and I have some difficulties.
I know there is a second list for "Ocaml Beginners" but its running on
Yahoo and the membership confirmation takes a while ...
So let me ask you, what is wrong with this code
let rec fac n = if n > 1 then n * fac (n-1) else 1 ;;
print_int fac(6);;
No matter if I compile this with ocamlc or run the commands with
ocaml, I always get the error:
/////////////////////////////////////////////////////////////////
File "ifelse.ml", line 2, characters 0-9:
This function is applied to too many arguments,
maybe you forgot a `;'
///////////////////////////////////////////////////////////////////
What is the problem here? Adding an additional ; doesn't help of course.
thanks
ben
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Error: This function is applied to too many arguments,maybe you forgot a `; '
@ 2008-08-04 1:00 Damien Guichard
2008-08-04 5:58 ` Yves Bertot
0 siblings, 1 reply; 5+ messages in thread
From: Damien Guichard @ 2008-08-04 1:00 UTC (permalink / raw)
To: caml-list
[-- Attachment #1: Type: text/plain, Size: 1353 bytes --]
Hi,
This line:
print_int fac(6);;
Can be read as:
print_int fac 6;;
That is 2 arguments whereas print_int expects exactly 1 argument.
The corrected line is:
print_int (fac 6);;
Note that function application is just juxtaposition, parenthesis are unneded.
Regards,
- damien
hi
I try to make my first steps with Ocaml and I have some difficulties.
I know there is a second list for "Ocaml Beginners" but its running on
Yahoo and the membership confirmation takes a while ...
So let me ask you, what is wrong with this code
let rec fac n = if n > 1 then n * fac (n-1) else 1 ;;
print_int fac(6);;
No matter if I compile this with ocamlc or run the commands with
ocaml, I always get the error:
/////////////////////////////////////////////////////////////////
File "ifelse.ml", line 2, characters 0-9:
This function is applied to too many arguments,
maybe you forgot a `;'
///////////////////////////////////////////////////////////////////
What is the problem here? Adding an additional ; doesn't help of course.
thanks
ben
_______________________________________________
Caml-list mailing list. Subscription management:
http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
Archives: http://caml.inria.fr
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs
[-- Attachment #2: Type: text/html, Size: 3012 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Caml-list] Error: This function is applied to too many arguments,maybe you forgot a `; '
2008-08-04 1:00 [Caml-list] Error: This function is applied to too many arguments,maybe " Damien Guichard
@ 2008-08-04 5:58 ` Yves Bertot
0 siblings, 0 replies; 5+ messages in thread
From: Yves Bertot @ 2008-08-04 5:58 UTC (permalink / raw)
To: Damien Guichard; +Cc: caml-list
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
argument.
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
enforced:
you don't put any parentheses around function arguments, unless it is
necessary
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
written
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
mathematicians
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.
Yves
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2008-08-05 13:29 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-04 0:46 Error: This function is applied to too many arguments, maybe you forgot a `;' Ben Aurel
2008-08-05 12:11 ` [Caml-list] Error: This function is applied to too many arguments, maybe you forgot a `; ' Richard Jones
2008-08-05 13:29 ` Peng Zang
2008-08-04 1:00 [Caml-list] Error: This function is applied to too many arguments,maybe " Damien Guichard
2008-08-04 5:58 ` Yves Bertot
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox