如何定义这个无点?
let argmax m = (fst.(maximumBy (comparing snd)).(zip [0..])) m
按预期工作。最合乎逻辑的似乎只是放弃m
这样的:
let argmax = (fst.(maximumBy (comparing snd)).(zip [0..]))
可以在 ghci 中定义,但是用它来调用它argmax [1,3,4,5,6,1]
给了我
<interactive>:103:9:
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 `argmax', namely `[1, 3, 4, 5, ....]'
In the expression: argmax [1, 3, 4, 5, ....]
我认为这与类型有关:
:t (fst.(maximumBy (comparing snd)).(zip [0..]))
:: (Enum c, Num c, Ord a) => [a] -> c
对于点版本:
argmax :: (Enum c, Num c, Ord a) => [a] -> c
对于无积分版本:
argmax :: [()] -> Integer
这是 ghci 诡异还是我做错了什么?