我真的需要帮助找到一种计算米兰达语言平均值的方法。我似乎得到了这个错误,它无法将类型 [num] -> num 与 num 统一起来。我似乎无法将列表的总和作为一个值并进行除法?
elements = 4
grades = [24, 12, 33, 17]
|| The code belows purpose is to get the sum of the list
ngrades == [num]
sumlist :: ngrades -> num
sumlist [] = 0
sumlist (front : rest) = front + sumlist rest
|| We calculate the average by getting the sum we calc above to the elements
avg = sumlist div elements
|| We compare each element reccursively to find the maximum value
maxi :: ngrades -> num
maxi [] = 0
maxi (front : []) = front[][1]
maxi (front : next : rest) = maxi (front : rest), if front > next
= maxi (next : rest), otherwise
|| We compare each element reccursively to find the minimum value
mini :: ngrades -> num
mini [] = 0
mini (front : []) = front
mini (front : next : rest) = mini (front : rest), if front < next
= mini (next : rest), otherwise
[1]: https://i.stack.imgur.com/2pYCq.jpg