是否可以访问monad变压器所需的monad的内部结构? [英] Is access to the internal structure of a monad required for a monad transformer?
问题描述
是否有必要访问
a monad的内部结构来编写monad变换器?
例如:我想要 GetT
- 转换为从Data.Binary.Get,
monad,但此模块不公开内部
获取获取
monad。这是否意味着我唯一的
方式是直接将 GetT
添加到Data.Binary.Get模块?
一般来说,是的。在这个例子中看到内部monad(这里是列表monad)如何撤消外部monad的早期动作的效果:
> execWriterT(tellHi>> tellHo>> lift [()])
[HiHo]
> execWriterT(tellHi>> tellHo>> lift [])
[]
现在假设您可以将每个monad变成monad变换器。然后你可以构造一个 IOT
monad变形器,这可以启动一个导弹,然后撤销它:
> execIOT(launchMissile>> lift [])
因此不可能将任意monad ,而不用看定义,转换成monad变压器。
Is it necessary to have access to the internal structure of a monad to write the monad transformer?
For example: I'd like to have GetT
- transformer for Get
monad from Data.Binary.Get,
but this module doesn't expose internals of Get
monad. Does it mean that the only
way for me is to add GetT
directly to Data.Binary.Get module?
In general, yes. See in this example how the the inner monad (here the list monad) can "undo" the effect of an "earlier" action of the outer monad:
> execWriterT (tell "Hi" >> tell "Ho" >> lift [()])
["HiHo"]
> execWriterT (tell "Hi" >> tell "Ho" >> lift [])
[]
Now assume you could turn every monad into a monad transformer. Then you would be able to construct a IOT
monad transformer, and this could would launch a missile but then undo it:
> execIOT (launchMissile >> lift [])
Hence it is not possible to turn an arbitrary monad, without looking at the definition, into a monad transformer.
这篇关于是否可以访问monad变压器所需的monad的内部结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!