[Haskell-cafe] Class Instances

Cetin Sert cetin.sert at gmail.com
Fri Feb 13 11:38:38 EST 2009


Hi,

class Processor a where
  ready :: (forall b c. a → [b → c])

{-
instance Processor (b → c) where
  ready = repeat

instance Processor [b → c] where
  ready = id-}

doSth :: (Show p, Processor p) ⇒ p → IO ()
doSth p = print p

-------------------------------
Why can I not declare the above instances and always get:

message.hs:229:10:
    Couldn't match expected type `b' against inferred type `b1'
      `b' is a rigid type variable bound by
          the instance declaration at message.hs:228:20
      `b1' is a rigid type variable bound by
           the type signature for `ready' at message.hs:226:19
      Expected type: b -> c
      Inferred type: b1 -> c1
    In the expression: repeat
    In the definition of `ready': ready = repeat

message.hs:229:10:
    Couldn't match expected type `c' against inferred type `c1'
      `c' is a rigid type variable bound by
          the instance declaration at message.hs:228:24
      `c1' is a rigid type variable bound by
           the type signature for `ready' at message.hs:226:21
      Expected type: b -> c
      Inferred type: b1 -> c1
    In the expression: repeat
    In the definition of `ready': ready = repeat

message.hs:232:10:
    Couldn't match expected type `b1' against inferred type `b'
      `b1' is a rigid type variable bound by
           the type signature for `ready' at message.hs:226:19
      `b' is a rigid type variable bound by
          the instance declaration at message.hs:231:20
      Expected type: [b1 -> c]
      Inferred type: [b -> c1]
    In the expression: id
    In the definition of `ready': ready = id

message.hs:232:10:
    Couldn't match expected type `c1' against inferred type `c'
      `c1' is a rigid type variable bound by
           the type signature for `ready' at message.hs:226:21
      `c' is a rigid type variable bound by
          the instance declaration at message.hs:231:24
      Expected type: [b -> c1]
      Inferred type: [b1 -> c]
    In the expression: id
    In the definition of `ready': ready = id

Is there a way around this?

Regards,
CS
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20090213/c18f2d5f/attachment.htm


More information about the Haskell-Cafe mailing list