gpt4 book ai didi

haskell - ApplicativeDo 不使用测序

转载 作者:行者123 更新时间:2023-12-04 22:56:58 25 4
gpt4 key购买 nike

我有这种类型,基本上是 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。

最佳答案

搜索 ApplicativeDo 后相关门票在GHC Trac ,看来这是一个已知问题:

  • https://ghc.haskell.org/trac/ghc/ticket/10892
  • https://ghc.haskell.org/trac/ghc/ticket/12666


  • 显式丢弃结果是一种解决方法:
    do
    _ <- pure ()
    pure ()

    关于haskell - ApplicativeDo 不使用测序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41210599/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com