Optimizing a Free Monad

牧云@^-^@ 提交于 2021-02-19 03:44:10

问题


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?

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.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/39794492/optimizing-a-free-monad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!