相关疑难解决方法(0)

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 …
Run Code Online (Sandbox Code Playgroud)

monads haskell do-notation applicative

4
推荐指数
1
解决办法
208
查看次数

标签 统计

applicative ×1

do-notation ×1

haskell ×1

monads ×1