什么是MonadBaseControl? [英] What is MonadBaseControl for?
问题描述
我正在深入研究Yesod的monad,并遇到 MonadBaseControl
。
我看了一下骇客文档,迷路了。有人可以告诉我它正在试图解决的问题吗?
liftBase
(或正如软件包文档所述,这种增强功能以及这些类型类的其余内容允许您提升函数,如 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屋!