In opposition of Functor as super-class of Monad

Tony Morris tmorris at tmorris.net
Tue Jan 4 14:38:33 CET 2011


I think you'll find a problem using do-notation with your Monad.

Tony Morris

On 04/01/2011 11:33 PM, "Alexey Khudyakov" <alexey.skladnoy at gmail.com>
wrote:

On 04.01.2011 13:24, oleg at okmij.org wrote:
>
>
> I'd like to argue in opposition of making Functor a...
I think I understood your point. But it looks like that it's possible to use
subclass's function in superclass instance. At very least GHC is able to do
it.

Following example works just fine without any language extensions in
GHC6.12.3


import Prelude hiding (Monad(..), Functor(..))

class Functor f where
 fmap :: (a -> b) -> f a -> f b



class Functor m => Monad m where
 return :: a -> m a
 (>>=) :: m a -> (a -> m b) -> m b
instance Functor Maybe where


 fmap f m = m >>= (return . f)
instance Monad Maybe where
 return = Just
 Nothing >>= _ = Nothing
 Just x  >>= f = f x



_______________________________________________
Haskell-prime mailing list
Haskell-prime at haskell.o...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-prime/attachments/20110104/acd6c77f/attachment.htm>


More information about the Haskell-prime mailing list