[Haskell-cafe] Function Precedence
Loup Vaillant
loup.vaillant at gmail.com
Tue Apr 1 08:05:34 EDT 2008
2008/4/1, Jules Bean <jules at jellybean.co.uk>:
> PR Stanley wrote:
> > Why can't we have
> > function application implemented outwardly (inside-out).
>
> No reason we can't.
>
> We could.
>
> We just don't.
>
> People have spent some time thinking and experimenting and have decided
> this way round is more convenient. It's certainly possible to disagree.
I bet this "time and thinking" involved currying. For instance, with:
f :: int -> int -> int
f a b = a + b + 3
Let's explore the two possibilities
(1) f 4 2 <=> (f 4) 2 -- don't need parentheses
(2) f 4 2 <=> f (4 2) -- do need parentheses: (f 4) 2
Curried functions are pervasive, so (1) just saves us more brakets
than (2) does.
> > f g x
> > returns an error because f takes only one argument.
Do not forget that *every* function take only one argument. The trick
is that the result may also be a function. Therefore,
f g 5 <=> id id 5 <=> (id id) 5 <=> id 5 <=> 5
indeed do run smoothly (just checked in the Ocaml toplevel, thanks to
Jerzy for pointing this out).
Loup
More information about the Haskell-Cafe
mailing list