如何定义这一点?
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的幽灵还是我做错了什么?