适用性不使用排序 [英] ApplicativeDo not working with sequencing

查看:129
本文介绍了适用性不使用排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这种类型,基本上是Kleisli箭头:

I have this type, basically a Kleisli arrow:

{-# 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表示法构建一个值:

Since it has an Applicative instance, I turn on ApplicativeDo and try to build a value using 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.

Is there a way to make it work? I'm using GHC 8.0.1.

推荐答案

After searching for ApplicativeDo-related tickets in the GHC Trac, it appears that is is a known problem:

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

明确丢弃结果是一种解决方法:

Explicitly discarding the result is a workaround:

do
  _ <- pure ()
  pure ()

这篇关于适用性不使用排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆