【发布时间】:2013-12-26 13:34:46
【问题描述】:
我正在尝试学习 Haskell,我已经阅读了 Learn you a Haskell 的第 6 章和第 7 章。为什么以下两个函数定义不给出相同的结果?我以为 (f . g) x = f (g (x))?
Def 1
let{ t :: Eq x => [x] -> Int; t xs = length( nub xs)}
t [1]
1
Def 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]
【问题讨论】:
标签: haskell