Control.MonadPlus.Free有什么问题? [英] What was wrong with Control.MonadPlus.Free?
问题描述
免费的MonadPlus 定义为
p> data Free fa = Pure a |免费(f(Free f a))|加上[免费发放]
已在 free 4.6中移除, (更新日志):
删除
Control.MonadPlus.Free
。使用FreeT f []
代替,结果将是守法的。
什么是问题,特别是什么法律没有持有? 根据问题,旧定义不遵守联想法。
虽然我对这种事情一无所知,但我怀疑还有一个问题是冗余:
纯a
加[纯a]
加[加[纯a]]
...
似乎都代表了同样的事情。自由结构通常被认为是独一无二的。有些时候,他们不能独特地表示(例如,自由阿贝尔团体),但是如果可能的话,他们应该是。实际上,我认为建议的替代方案遭受同样的问题,但可以通过使用 NonEmpty
而不是 []
来修复它。所以这种改变可能只是为了从图书馆中删除多余的东西。
The free MonadPlus defined as
data Free f a = Pure a | Free (f (Free f a)) | Plus [Free f a]
was removed in free 4.6 with the following remark (changelog):
Removed
Control.MonadPlus.Free
. UseFreeT f []
instead and the result will be law-abiding.
What was the problem, in particular, what laws didn't hold?
According to this issue in the bug tracker the old definition does not obey the associative law.
Although I know little about such things, I suspect an other problem is redundancy:
Pure a
Plus [Pure a]
Plus [Plus [Pure a]]
...
all seem to represent the same thing. Free structures are generally supposed to be unique. There are times when they cannot be represented uniquely (e.g., free abelian groups) but when possible they should be.
Actually, I think the suggested alternative suffers from the same problem, although it might be possible to repair it by using NonEmpty
instead of []
. So this change could just be a matter of removing excess cruft from the library.
这篇关于Control.MonadPlus.Free有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!