[Haskell-cafe] Why do I have to specify (Monad m) here again?

Marc Weber marco-oweber at gmx.de
Sun Feb 18 11:32:54 EST 2007


On Sun, Feb 18, 2007 at 05:06:33PM +0300, Bulat Ziganshin wrote:
> Hello Marc,
> 
> Sunday, February 18, 2007, 5:21:36 PM, you wrote:
> 
> > Why do I have to specify (Monad m) here again?
> 
> > class (Monad m) =>> GetMV m a where
> 
> > instance GetMV m c where
> 
> because you can find another way to ensure that m is monad. for
> example,
> 
> instance (MonadIO m) => GetMV m c where
> 
> if i not yet proposed you to read
> http://haskell.org/haskellwiki/OOP_vs_type_classes
> then now it is time to do it :)

I think I've read it once. But I'll do it again more thoroughly ..

I'll try to explain why I don't get it yet

	class (Monad m) => GetMV m a where (1)

tells that the first param called 'm' is an instance of class m, right?
Then it doesn't matter wether I use
	instance GetMV m          c where 
or
	instance GetMV <any name> c where

If the class sepecification (1) forces m to be a monad, <any name> has to be
one, too(?)

When using your example (Monad IO):
	class (Monad m) => MonadIO m where
		liftIO :: IO a -> m a
it it basically the same, isn't it?  This declaration forces m to be monad..
which would't hurt if GHC would infer m beeing a monad automatically?

Marc


More information about the Haskell-Cafe mailing list