[Haskell-cafe] const is question
Sebastiaan Visser
sfvisser at cs.uu.nl
Sat Jun 14 12:23:52 EDT 2008
On Jun 14, 2008, at 6:14 PM, odtaa48 wrote:
> hello
> could someone explain the following differing results const id 0
> 5 -> 5 -- ie. 'takes' the 'last' one
> const (id 0) 5 -> 0 -- ie. 'takes' the 'first' one
>
> Thanks
You can easily see what is happening by rewriting the equations step
by step. Remember that the const function is (\x y -> x) and the id
function is (\x -> x).
Example 1:
const id 0 5
== (const id 0) 5
== id 5
== 5
Example 2:
const (id 0) 5
== const 0 5
== 0
So, in both cases const takes the first.
--
Sebastiaan.
More information about the Haskell-Cafe
mailing list