Applicative not a Monad superclass right now
instance Monad m where ... -- this is how it is today, instead of instance Applicative m => Monad m where ...
but it is planned that in GHC 7.10 this will be changed so that Applicative Monad superclass. To help with the transition, a warning will appear in GHC 7.7 and 7.8 that you saw when the GHC encounters Monad without an Applicative instance.
Now a bit confusing bit is that all valid Monad are applicative functors, even if they are not instance of Applicative . We can write
fmapM :: Monad m => (a -> b) -> ma -> mb fmapM f ma = ma >>= return . f -- aka `liftM` pureM :: Monad m => a -> ma pureM = return ap :: Monad m => m (a -> b) -> ma -> mb ap mf ma = do { f <- mf; a <- ma; return (fa) } -- aka `ap`
which together satisfy the signature and laws of Functor and Applicative . This is why the restriction of the superclass makes sense to add a purely historical catastrophe that it was not in the first case - Applicative was discovered and popularized far after Monad .
newtype WrappedMonad ma = WM (ma) instance Monad m => Functor (WrappedMonad m) where fmap f (WM m) = WM (liftM fm) instance Monad m => Applicative (WrappedMonad m) where pure = WM . return WM mf <*> WM ma = WM $ mf `ap` ma
For more information on how Applicative and Monad relate, take a look at the answer I wrote earlier here: Is it better to define Functor from the applicative point of view in terms of Monad or vice versa?
J. abrahamson
source share