[Haskell-beginners] Inferred type is less polymorphic than e

Marco Túlio Gontijo e Silva marcot at holoscopio.com
Wed Apr 8 18:29:24 EDT 2009


Hello,

I'm getting this error message from GHC in the following code:


> type M a = Monad m => m a

> class A a b where
>   f :: Monad m => a -> m b

> instance A String Char where
>   f string = return $ head string

> instance A Char Int where
>   f int = return $ fromEnum int

I thought at first to write h like this, but it gives me the error.  If
I write it like the other h uncommented, there's no error.  I can't see
why they aren't equivalent.

h :: IO ()
h = f "abc" >>= (f :: Char -> M Int) >>= print

> h :: IO ()
> h = (f "abc" :: M Char) >>= f >>= (print :: Int -> IO ())

Can someone clarify this to me?

Greetings.

-- 
marcot
http://marcot.iaaeee.org/




More information about the Beginners mailing list