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

问题描述

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

推荐答案

ApplicativeDo相关的票证之后noreferrer> GHC Trac ,看来这是一个已知问题:

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 ()

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

07-31 16:00