0

I'm defining a data an instance Monad just for utilizing the do notation. However, by the Applicative-Monad Proposal implemented in GHC 7.10+, I will have to also define the data as an instance of Applicative and Functor. I don't plan to define fmap, pure, <*>, as they are easily derived from liftM, return and ap in terms of Monad.

To make Applicative a superclass of Monad explicitly is good. However, is it the case that AMP also introduces some really unnecessary code on writing those part that are totally useless? Or if Haskell has some short hand ways to cope with this situation? Some like:

class Applicative m => Monad m where
   super pure = return
   super (<*>) = ap
   return :: a -> m a
   (>>=) :: m a -> (a -> m b) -> m b
duplode
  • 33,731
  • 7
  • 79
  • 150
shouya
  • 2,863
  • 1
  • 24
  • 45
  • 1
    While I would like to have such a feature, I really don't see much need for it in case of AMP. `instance Applicative YourFunctor where {pure=return; (<*>)=ap}`. There, is that really too much boilerplate for you? – Besides, often it _is_ a good idea to write out the `Applicative` instance manually; sometimes it can be much more efficient than a `Monad`-derived version. And `Functor` you normally don't need to define at all, just use `-XDeriveFunctor`. – leftaroundabout Nov 21 '15 at 15:13
  • 2
    @leftaroundabout: Although writing the data as an instance `Applicative` could be not that long, it is still a boilerplate. I know that sometimes implementing an `Applicative` instance would be more efficient but what I want is the choice, so I could only write that down when I really wanted. – shouya Nov 21 '15 at 15:20

0 Answers0