什么是MonadBaseControl? [英] What is MonadBaseControl for?

查看:84
本文介绍了什么是MonadBaseControl?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在深入研究Yesod的monad,并遇到 MonadBaseControl
我看了一下骇客文档,迷路了。有人可以告诉我它正在试图解决的问题吗?

/hackage.haskell.org/package/monad-control\">monad-control ,它是一对类型类中的一个(另一个是MonadTransControl ),以增强 MonadBase MonadTrans )通过为实现它的monad支持替代 liftBase (或 lift )操作。这个增强的版本不再需要在绝对基地monad(即立即基地monad)中采取简单行动,而是采用了一个函数,该功能在此时获得基地monad(或monad变换器)的整个状态作为它的唯一参数并返回前面提到的动作。

正如软件包文档所述,这种增强功能以​​及这些类型类的其余内容允许您提升函数,如 catch alloca forkIO 基本monad(即时基本monad),这对于 MonadBase (分别为MonadTrans ),因为后一对不允许你提取函数的参数,只是结果,而 monad-control 同时允许这两个选项。



结果,monad组合(resp。 monad变压器),可以与 MonadBaseControl (分别 MonadTransControl )是一组monad的严格子集,可以与MonadBase (分别为 MonadTrans ),但前者的组合比后者强大得多同样的道理。


I'm digging deeper into Yesod's monads, and have encountered MonadBaseControl. I took a look at the hackage doc, and got lost. Could someone tell me the problem it is trying to solve?

解决方案

It comes from the package monad-control, and is one of a pair of type classes (the other one being MonadTransControl) that enhance MonadBase (resp. MonadTrans) by supporting an alternative liftBase (resp. lift) operation for monads that implement it. This enhanced version no longer takes a simple action in the absolute base monad (resp. immediate base monad), but instead takes a function that gets the base monad's (resp. monad transformer's) whole state at that point as its only parameter and returns the aforementioned action.

As the package documentation states, this enhancement, along with the rest of the contents of these type classes, allow you to lift functions like catch, alloca, and forkIO from the absolute base monad (resp. immediate base monad), which is not possible with the simpler scheme present in MonadBase (resp. MonadTrans) because the latter pair do not allow you to lift the arguments of a function, just the results, while the approach taken by monad-control allows both.

As a result, the set of monads (resp. monad transformers) that can be used with MonadBaseControl (resp. MonadTransControl) is a strict subset of the set of monads that can be used with MonadBase (resp. MonadTrans), but the former groups are much more powerful than the latter for the same reason.

这篇关于什么是MonadBaseControl?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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