作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在用 Haskell 编写一个函数来从任何 ListLike
制作直方图与 Ord
元素:
import qualified Data.ListLike as LL
...
frequencies :: (Ord x, LL.ListLike xs x) => xs -> [(x, Int)]
frequencies xs = LL.map (\x->(LL.head x, LL.length x)) $ LL.group $ LL.sort xs
Ambiguous type variable `full0' in the constraint:
(LL.ListLike full0 xs) arising from a use of `LL.group'
Probable fix: add a type signature that fixes these type variable(s)
In the expression: LL.group
In the second argument of `($)', namely `LL.group $ LL.sort xs'
In the expression:
LL.map (\ x -> (LL.head x, LL.length x)) $ LL.group $ LL.sort xs
LL.group
有类型
(ListLike full0 full, ListLike full item, Eq item) => full -> full0
对应于
(Eq a) => [a]->[[a]]
就普通列表而言。
full
作为元素”这样的类型,即
full0
?
最佳答案
Is Haskell somehow unable to infer that there is such a type as "ListLike with
full
as elements", i.efull0
?
full0
from 并且 Haskell 编译器不知道使用哪个。想一想:一般来说,可以有不止一种类型
full0
这是一个类似列表的类型,带有
full
作为元素:
[full]
或
Data.Sequence.Seq full
或许多其他选择。并且因为
LL.map
定义的一般性,
full0
不限于
[full]
来自函数的返回类型
frequencies
.
full0
至
[full]
,一种方法是替换
LL.map
在
frequencies
的定义中与普通的旧
map
对于列表。
关于haskell - 使用 ListLike 的二义性类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6404989/
我正在用 Haskell 编写一个函数来从任何 ListLike 制作直方图与 Ord元素: import qualified Data.ListLike as LL ... frequencies
有人可以帮我理解集合API中Scala的各种“喜欢”特征。我一直在阅读并尝试比较每个没有运气的人。我想我可以看到Map例如扩展了MapLike-添加了2种具体方法。但这引出了为什么要这样做的问题?为什
我是一名优秀的程序员,十分优秀!