0
這是我的函數:添加一個實例聲明哈斯克爾
bestLocByArtiest :: String -> [Review] -> Double
bestLocByArtiest art = rev
where gmloc = [gemZaalByArtiest art, gemFestByArtiest art, gemOpenByArtiest art]
rev = max gmloc
這是錯誤我得到:
Review.hs:101:24:
Couldn't match type `[Review] -> Double' with `Review'
Expected type: [Review] -> Double
Actual type: [[Review] -> Double] -> [[Review] -> Double]
In the expression: rev
In an equation for `bestLocByArtiest':
bestLocByArtiest art
= rev
where
gmloc = [gemZaalByArtiest art, ....]
rev = max gmloc
,所以我希望有人能解釋我這個錯誤是什麼手段,我有什麼改變我的代碼來解決它。
編輯 通過改變最大最大我得到這個新的錯誤:
Review.hs:103:21:
No instance for (Ord ([Review] -> Double))
arising from a use of `maximum'
Possible fix:
add an instance declaration for (Ord ([Review] -> Double))
In the expression: maximum gmloc
In an equation for `rev': rev = maximum gmloc
In an equation for `bestLocByArtiest':
bestLocByArtiest art
= rev
where
gmloc = [gemZaalByArtiest art, ....]
rev = maximum gmloc
這是什麼意思?
'max'最大值爲2,而不是N個元素的列表。你想'最大'。另外,你似乎不接受你的第二個參數('[Review]')。 –