[Haskell-cafe] A Typing Dilemma

John Goerzen jgoerzen at complete.org
Fri Oct 8 09:57:03 EDT 2004

Thanks so much for all the help many of you have provided.  I have one
(heh) more question:

I have this code:

defaultHandler :: LogHandler b => IO (a -> IORef b)
defaultHandler = do
                 h <- (streamHandler stdout WARNING)
                 r <- newIORef h
                 return (\x -> r)

The idea is to create a new IORef to something in the LogHandler class
and return a function that returns it.  The thing returned by that call
to streamHandler is in the LogHandler class.  Specifically, its
declaration looks like this:

instance LogHandler (GenericHandler a) where

and streamHandler returns a "GenericHandler Handle" object.

Now, when compiling that defaultHandler code, the compiler complains:

    Cannot unify the type-signature variable `b'
        with the type `MissingH.Logging.Handler.Simple.GenericHandler
        Expected type: IORef b
        Inferred type: IORef
    In a lambda abstraction: \ x -> r
    In the first argument of `return', namely `(\ x -> r)'

I'm stumped.  Can anyone shed some light on that for me?


-- John

More information about the Haskell-Cafe mailing list