此实现工作正常:
λ > let maximum' xs = foldl1 max xs
λ > maximum' [1..5]
5
由于currying,我们可以将foo a = bar b a
之类的函数重写为foo = bar b
foldl1 max
预期类型的结果
λ > :t foldl1 max
foldl1 max :: Ord a => [a] -> a
但这不起作用
λ > let maximum' = foldl1 max
λ > maximum' [1..5]
<interactive>:71:11:
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 maximum', namely `[1 .. 5]'
In the expression: maximum' [1 .. 5]
在这种情况下,这个错误对我来说并不清楚。那么,为什么会出现这种错误?有没有办法解决它并定义这样的函数而不明确指定最后一个参数?