[Haskell-cafe] ok, someone check me on this (type unification
from the (>>=)/fmap thread)
Matthew Brecknell
haskell at brecknell.org
Sun May 10 17:24:06 EDT 2009
Brandon S. Allbery KF8NH wrote:
> I can't tell where I'm making the mistake here.
In Just 3 >>= (+1), we have, with some alpha conversions to make the
unification easier to follow:
Just 3 :: Num i => Maybe i -- (1)
(>>=) :: m a -> (a -> m b) -> m b -- (2)
(+1) :: Num n => n -> n -- (3)
Unify (1) with the first argument in (2):
Maybe i ~ m a
m ~ Maybe -- (4)
i ~ a -- (5)
Unify the second argument in (2) with (3):
(n -> n) ~ (a -> m b)
n ~ a -- (6)
n ~ m b -- (7)
Substitute (4) in (7):
n ~ Maybe b -- (8)
But we have (Num n), so from (8), we need (Num (Maybe b)). Since there
is no such instance, we get the error.
Your question seems to be whether some other error should have come up
first.
>From (5) and (6), we get:
n ~ i -- (9)
And from (8):
i ~ Maybe b -- (10)
Again, we have (Num i), so from (10), we need (Num (Maybe b)). Same
error, different route.
Perhaps you are assuming that i defaults to Integer before the
type-checking completes, and are therefore expecting that (10) should
produce a unification error before contexts are checked?
Regards,
Matthew
More information about the Haskell-Cafe
mailing list