我在学习哈斯克尔,我一直在回顾第6章和第7章学习哈斯克尔。为什么下面两个函数定义没有给出相同的结果?我认为(f。g)x = f(g(x))?哈斯克尔函数组合混淆
防守1
let{ t :: Eq x => [x] -> Int; t xs = length(nub xs)}
t [1]
1
防守2
let t = length . nub
t [1]
<interactive>:78:4:
No instance for (Num()) arising from the literal `1'
Possible fix: add an instance declaration for (Num())
In the expression: 1
In the first argument of `t', namely `[1]'
In the expression: t [1]
我在什么时候它变得不可能指的是单态的限制,而不在前面加上形容词“可怕的” :) –
@ChrisTaylor想禁用它:对于这一现象的技术术语是“epitheton奥尔南”。 –