dan*_*iaz 4 monads haskell do-notation applicative
我有这种类型,基本上是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 from a do statement
Run Code Online (Sandbox Code Playgroud)
有没有办法让它发挥作用?我正在使用GHC 8.0.1.
在GHC Trac中搜索ApplicativeDo相关票证后,似乎是一个已知问题:
明确丢弃结果是一种解决方法:
do
_ <- pure ()
pure ()
Run Code Online (Sandbox Code Playgroud)