优化免费Monad [英] Optimizing a Free Monad

查看:62
本文介绍了优化免费Monad的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个值 a:Free [Op,A] ,是否可以展平" a 的结构,以便两个 Op <由自由单子绑定在一起的/code>可能会折叠成一个吗?

If I have a value a: Free[Op, A], is it possible to "flatten" the structure of a so that two Ops that are bound together by the free monad may be collapsed into one?

上下文:我想在解释之前将其作为优化步骤执行,因为 Op 的语义是其运算是幂等的.因此,如果两个连续"出现,则可以在不增加程序语义的情况下消除第二个.

Context: I'd like to perform this as an optimization step before interpretation because a semantic of Op is that its operations are idempotent. So if two appear "in a row", the second can be eliminated at no cost to the semantics of the program.

推荐答案

据我所知,Free Monad程序无法进行这种自省,因为它表示顺序计算,其中每一步都取决于另一步的结果.

As far as I understand there is no way for this kind introspection of Free Monad program as it represents sequential computation where each step depends on the result of another.

约翰·德·戈斯(John de Goes)在Free Monad vs Free Applicative( https://www.youtube.com/watch?v=H28QqxO7Ihc ).后者具有内省的力量.

There is a great talk by John de Goes about the pros and cons of Free Monad vs Free Applicative (https://www.youtube.com/watch?v=H28QqxO7Ihc). The latter gives power of introspection.

这篇关于优化免费Monad的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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