本文介绍了MonoFoldable会让我们失去什么吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MonoFoldable mono-traversable 包中似乎可以实现所有通常的可折叠容器等,例如,可以将Bytestring和同构元组之类的内容做成MonoFoldable,但不能做成Foldable.我的问题是,除了需要一些高级GHC功能之外,我们是否从MonoFoldable中丢失了Foldable中没有的所有内容,这使实例编写者变得更加棘手,并且可能收到更丑陋的错误消息?

MonoFoldable in the mono-traversable package seems to be able to implement all of the usual Foldable containers and more, for example, things like Bytestring and homogeneous tuples can be made MonoFoldable but not Foldable. My question is, do we lose anything from MonoFoldable that we don't have in Foldable, aside from requiring some advanced GHC features, making it slightly more tricky for instance writers and perhaps getting uglier error messages?

例如,是否存在一些代码,例如,在使用Foldable进行编译时却无法推断出具有MonoFoldable类型的代码?还是让Foldable客户端(而不是实例编写器代码)比MonoFoldable简单得多的其他方法?

For example, is there some code which when using Foldable compiles but with MonoFoldable types are not inferred for example? Or anything else that makes client (not instance writer code) significantly simpler with Foldable than MonoFoldable?

推荐答案

您失去了参数性.

类型(Foldable f) => f a -> [a]提供的保证与(MonoFoldable c) => c -> [Element c]明显不同.

A type (Foldable f) => f a -> [a] provides significantly different guarantees than (MonoFoldable c) => c -> [Element c].

您可以使用免费的定理生成器来获得有关属性的一些想法,但是作为一个简单示例,前一种类型提供了属性,使得输出中的任何元素都必须出现在输入中.后者绝对不能保证此属性.

You can play with a free theorem generator to get some ideas of the properties, but as a simple example the former type provides the property that any element in the output must occur in the input. This property is in no way guaranteed by the latter type.

这篇关于MonoFoldable会让我们失去什么吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 19:44