>
> I'm going to ask a very stupid question.
>
> Why on earth is len computed twice in this example? I really don't
> understand this!
I have to confess that I mischievously hoped that someone
would say this: it demonstates the point nicely that
lifting the monomorphism restriction would cause at least
some people to be surprised.
Let me add the type signatures [I'm a bit puzzled why length used
to have type Integral b => ... but that's a side issue.]
length :: forall a b. Num b => [a] -> b
f :: forall a c. Num c => [a] -> c
f xs = if len > (3::Integer) then len else 0
where
len :: forall d. Num d => d
len = length xs
The first use of len returns an Integer, so we must compute
the length at type Integer.
The second use of len returns a value of type c, so we must
compute length at type c. (Someone *might* call f wanting an Integer
back, they might not.)
And there you have it.
Simon