我刚刚开始使用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]
Run Code Online (Sandbox Code Playgroud)
我将'统计'称为:
statistics[4,6,4,6]
Run Code Online (Sandbox Code Playgroud)
这导致模式匹配失败,而我期望看到:(4,5,2)
statistics[6]
Run Code Online (Sandbox Code Playgroud)
给出答案:(1,6,0)(这是正确的).有人能告诉我为什么我的第一个电话会导致这种模式匹配?因为我很确定我会列出一个列表作为参数