我剛開始使用Haskell,偶然發現問題。根據Haskell,我有一個模式匹配失敗,但我看不出如何。 這是我嘗試執行代碼:Haskell中的列表中的模式匹配失敗
statistics :: [Int] -> (Int, Int, Int)
statistics [gradelist] = (amountParticipants, average, amountInsufficient)
where
amountParticipants= length [gradelist]
average= sum[gradelist] `div` amountParticipants
amountInsufficient= length [number| number<- [gradelist], number<6]
我稱之爲與 '統計':
statistics[4,6,4,6]
這會導致模式匹配失敗,而我希望看到:(4,5,2 )
statistics[6]
給出了答案:(1,6,0)(這是正確的)。 有人能告訴我爲什麼我的第一個電話會導致這種模式匹配嗎?因爲我敢肯定,我給一個列表作爲參數
'[gradelist]'只匹配一個元素的列表。整個過程只使用'gradelist'。 – 2013-03-26 13:55:42