我有这种类型,基本上是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)
Run Code Online (Sandbox Code Playgroud)
由于它有一个Applicative实例,我打开ApplicativeDo并尝试使用do-notation构建一个值:
{-# language ApplicativeDo #-}
myplan :: Plan IO () ()
myplan = do
pure ()
pure ()
Run Code Online (Sandbox Code Playgroud)
它不起作用:
No instance for (Monad (Plan IO ())) arising …Run Code Online (Sandbox Code Playgroud)