Hoopl 中重写函数内的单子效应示例?
Hoopl 中的(前向)重写函数的类型由 mkFRewrite
函数:
mkFRewrite :: (FuelMonad m) =>
(forall e x.
n e x
-> f
-> m (Maybe (hoopl-3.8.6.1:Compiler.Hoopl.Dataflow.Graph n e x)))
-> FwdRewrite m n f
m
类型意味着我可以在重写时使用单子效果。论文“Hoopl:模块化,用于数据流分析和转换的可重用库” 在第 4.3 节“重写函数和客户端的 monad”中也有同样的说法。
谁能给我一个重写函数的例子,其中嵌入了非Hoopl单子效果?例如,使用 State monad 或执行某些 IO 的重写器。
The type of (forward) rewriting functions in Hoopl is given by the mkFRewrite
function:
mkFRewrite :: (FuelMonad m) =>
(forall e x.
n e x
-> f
-> m (Maybe (hoopl-3.8.6.1:Compiler.Hoopl.Dataflow.Graph n e x)))
-> FwdRewrite m n f
The m
type implies that I can use monadic effects while rewriting. The paper "Hoopl: A Modular, Reusable Library for Dataflow Analysis and Transformation" says the same in Section 4.3, "The rewrite function and the client's monad."
Can anyone give me an example of a rewrite function that has non-Hoopl monadic effects embedded inside it? For example, a rewriter that uses a State monad or does some IO.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这应该很简单,只需追逐类型即可。
您需要值
FwdRewrite mn f
和自定义值m
,因此您可以将其传递给以下函数:因此对
m
的唯一约束code> 你所拥有的是它是一个CheckpointMonad
;然后,当您运行该通行证时,您将获得您可以自己运行的最终单子值。事实上,GHC 的 Hoopl 将
m
用作SimplUniqMonad
,因此我们可以在对图进行操作时获得新的标签。This should be pretty simple, just chase the types.
You want a value of
FwdRewrite m n f
with a custom value ofm
, so you can pass it to the following function:So the only constraint on
m
you have is that it is aCheckpointMonad
; then when you run the pass you'll get the final monadic value which you can run yourself.In fact, GHC's Hoopl passes use with
m
as aSimplUniqMonad
, so we can get fresh labels while we're operating on the graph.