ben*_*ofs 2 haskell monad-transformers haskell-pipes
使用管道,我试图为ProxyFast或ProxyCorrect类型编写MonadTransControl的实例。这就是我得到的:
instance MonadTransControl (ProxyFast a' a b' b) where
  data StT (ProxyFast a' a b' b) a = StProxy { unStProxy :: ProxyFast a' a b' b Identity a}
  liftWith = undefined
  restoreT = undefined
我不知道如何编写liftWith或restoreT。其他monad转换器的实例都使用“交换” monad的函数,例如EitherT ema-> m(EitherT e Identity a),但是我在管道中找不到任何这样的函数。用于ProxyCorrect / ProxyFast的MonadTransControl的实例如何?还是不可能写一个?(如果是,则在管道4.0中可以吗?)
感谢您的链接,现在我可以给出更好的答案。
否,无法使用的任一版本来实现此目的pipes。原因是MonadTransControl希望将monad变压器构建在基础基本monad的单层之上。对于MonadTransControl当前实现的所有monad转换器都是如此,例如:
ErrorT  ~ m (Either e r)
StateT  ~ s -> m (r, s)
WriterT ~ m (r, w)
ReaderT ~ i -> m r
ListT   ~ m [r]  -- This version of ListT is wrong, and the true ListT
                 -- would not work for `MonadTransControl`
但是,a Proxy不会包装基本monad的单层。这两种pipes版本都适用,您可以根据需要嵌套任意数量的基本monad层。
实际上,将基本monad多次嵌套的任何monad转换器都会违抗MonadTransControl实例,例如:
FreeT     -- from the `free` package
ListT     -- when done "right"
ConduitM  -- from the `conduit` package
但是,仅仅因为pipes不执行MonadTransControl并不意味着所有的希望都会丢失。  pipes-safe实现人们通常会期望的许多操作MonadTransControl,例如bracket获取资源,因此,如果您可以详细说明您的特定用例,那么我可以告诉您是否存在pipes针对您问题的适当解决方案。
| 归档时间: | 
 | 
| 查看次数: | 181 次 | 
| 最近记录: |