I have this type, basically a Kleisli arrow:
{-# language DeriveFunctor #-}
data Plan m i o = Plan (i -> m o) deriving Functor
instance (Monad m) => Applicative (Plan m i) where
pure x = Plan (\_ -> pure x)
Plan f <*> Plan x = Plan (\i -> f i <*> x i)
Since it has an Applicative
instance, I turn on ApplicativeDo
and try to build a value using do-notation:
{-# language ApplicativeDo #-}
myplan :: Plan IO () ()
myplan = do
pure ()
pure ()
It doesn't work:
No instance for (Monad (Plan IO ())) arising from a do statement
Is there a way to make it work? I'm using GHC 8.0.1.
After searching for
ApplicativeDo
-related tickets in the GHC Trac, it appears that is is a known problem:https://ghc.haskell.org/trac/ghc/ticket/10892
https://ghc.haskell.org/trac/ghc/ticket/12666
Explicitly discarding the result is a workaround: