[Haskell-beginners] Rigid type variables match error

Darryn djreid at aapt.net.au
Fri Jun 26 20:48:02 EDT 2009


Hi, I wonder if anyone can explain what is going on here and what to do
about it. I'm fairly new to Haskell, so apologies in advance if my
question seems naive. I've cut my code down to a minimum that reproduces
the problem. I receive an error in GHCI in the following code,
complaining that it cannot match the rigid type variables for the
instance definition for Ainst for the function a3. Can anyone advise
about what to do about it?

------------------------------------------------
class A a where
    a1 :: a
    a2 :: a -> a
    a3 :: (B b) => b -> a

class B b where
    b1 :: Int -> b

data (B b) => Ainst b = I | J (Ainst b) | K b

instance (B b) => A (Ainst b) where
    a1 = I
--  a2 :: (B b, A a) => a -> a
    a2 = J
--  a3 :: (B b, A a) => b -> a
    a3 = K                 -- Error!
--  a3 = K `asTypeOf` a3   -- Error even with this!

data Binst = Val Int

instance B Binst where
    b1 = Val
------------------------------------------------

Test5.hs:17:9:
    Couldn't match expected type `b1' against inferred type `b'
      `b1' is a rigid type variable bound by
           the instance declaration at Test5.hs:12:12
      `b' is a rigid type variable bound by
          the type signature for `a3' at Test5.hs:5:13
      Expected type: b -> Ainst b1
      Inferred type: b -> Ainst b
    In the expression: K `asTypeOf` a3
    In the definition of `a3': a3 = K `asTypeOf` a3
Failed, modules loaded: none.





More information about the Beginners mailing list