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

[Caml-list] Calling a function with a self-defined type as argument
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
 Date: 2002-08-22 (13:59) From: Sven LUTHER Subject: Re: [Caml-list] Calling a function with a self-defined type as argument
```On Thu, Aug 22, 2002 at 02:47:26PM +0200, Oliver Bandel wrote:
>
> On 22 Aug 2002, Dimitri Ara wrote:
>
> > Oliver Bandel <oliver@first.in-berlin.de> a écrit :
> >
> > > (*
> > >    let _ = x Line "h0oifdaji oi" ;;
> > >    This last one does not work: => "This function is applied to too many arguments"
> > >
> > >    let _ = x Line( "reuruhjf" ) ;;
> > >    This last one does not work: => "This function is applied to too many arguments"
> > >
> > >    But it works in this way:
> > >    let _ = x (Line "reuruhjf") ;;
> > >
> > >    WHY?         (why *only* that?)
> > >
> > >    At least the second example (with parantheses around the
> > >    Line's arguments) should work...?!
> > > *)
> >
> > Because :
> >
> > (1) application is left associative.
> >
> > Thus `f x y' means `(f x) y' and
> >      `x Line ""' means `(x Line) ""'.
> >
> > (2) parentheses don't delimit the arguments of a function or a
> >     constructor but only fix the precedence of an expression.
> >
> > Thus f x (y) means f x y and
> >      `x Line ("")' means `x Line ""'.
>
> OK.
> But why has the Line()-argument not a higher pruiority than the
> function-call?
> The Line()-argument is only complete, if it get's it's
> args. And the type-declaration says in detail, how to
> handle the Line().

No, in ocaml, the function application is the space ' ', so what you are
used to write "f(x)", is just plain "f x", and you can add a few ( to
make unambigous, as in your case : (f x).

It seems confusing if you are not used to it, but makes for more clearer code.

Friendly,

Sven Luther
-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners

```