我有这种类型,基本上是 Kleisli 箭头:
{-# 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)
由于它有一个Applicative
实例,我打开ApplicativeDo
并尝试使用 do-notation 构建一个值:
{-# language ApplicativeDo #-}
myplan :: Plan IO () ()
myplan = do
pure ()
pure ()
它不起作用:
No instance for (Monad (Plan IO ())) arising from a do statement
有没有办法让它工作?我正在使用 GHC 8.0.1。