我刚开始使用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