[Haskell-cafe] Function const (Binding)
Daniel Fischer
daniel.is.fischer at web.de
Sat Feb 7 18:38:49 EST 2009
Am Sonntag, 8. Februar 2009 00:24 schrieb TKM:
> Hello,
>
> I've a small question about the function const. I'm a bit of confused about
> how it binds. Let me take the following expression as example:
>
> const id 1 2
>
> If I execute this expression, I will get as answer 2 with Helium. Now is my
> question, why doesn't it give me 1 as the answer? Because the type of id
> would be: a -> a. So first it would execute id 1 in my opinion. That gives
> us 1. And after executing const 1 2 it should give us 1.
>
> Can somebody explain to me why it does not bind as I expect? (I know I can
> do: const (id 1) 2 to get what I want)
>
> Thank you for your answers.
>
> Greetz TKM
Function application associates to the left, so
f a b c d
is the same as
(((f a) b) c) d
and in your example
const id 1 2 === ((const id) 1) 2,
so first (const id) is evaluated, that is then applied to 1 and finally the
result of const id 1 is applied to 2.
Now (const x) === \y -> x, so (const id) 1 is id and id 2 === 2.
HTH,
Daniel
More information about the Haskell-Cafe
mailing list