I have been trying a little example from the answer to this question:
liftTup :: (x -> f x) -> (a, b) -> (f a, f b)
liftTup liftFunc (t, v) = (liftFunc t, liftFunc v)
This clearly needs forall
quantifier to work, but I am trying to understand the error message syntax to be able to know what's wrong if I get similar ones in future. So for this one I get:
monad.hs:112:28-37: Couldn't match type `x' with `b' …
`x' is a rigid type variable bound by
the type signature for
liftTup :: (x -> f x) -> (a, b) -> (f a, f b)
at /Users/user/monad.hs:111:12
`b' is a rigid type variable bound by
the type signature for
liftTup :: (x -> f x) -> (a, b) -> (f a, f b)
at /Users/user/monad.hs:111:12
Expected type: f a
Actual type: f x
In the return type of a call of `liftFunc'
In the expression: liftFunc t
In the expression: (liftFunc t, liftFunc v)
monad.hs:112:40-49: Couldn't match type `a' with `b' …
`a' is a rigid type variable bound by
the type signature for
liftTup :: (x -> f x) -> (a, b) -> (f a, f b)
at /Users/user/monad.hs:111:12
`b' is a rigid type variable bound by
the type signature for
liftTup :: (x -> f x) -> (a, b) -> (f a, f b)
at /Users/user/monad.hs:111:12
Expected type: f b
Actual type: f x
In the return type of a call of `liftFunc'
In the expression: liftFunc v
In the expression: (liftFunc t, liftFunc v)
So as far as I can tell the first error is related to applying liftFunc
to t
for the first time, so it tries to match f x
with f a
. But how is b
related to this at all? b
only appears in the second element of the tuple.
The second error I guess comes from the fact that a
was matched to x
in the previous liftFunc
application, and now we are trying to match it to b
in the second one, but that doesn't quite work. Is this right?
What's the correct way to read these error messages and what's the relation between variables mentioned in "Couldn't match type .. with .." and variables mentioned in "Expected type: .. Actual type: .. " messages?