Question 3-1

Write a Haskell function countZeroes that takes a list of integers as a parameter and returns the number of zeroes contained in the list. For example, if I called countZeroes [5,0,0,8,0], it should return 3, since the list contains three zeroes.

Solution

countZeroes [] = 0
countZeroes (0:xs) = 1 + countZeroes xs
countZeroes (_:xs) = countZeroes xs

Back to Quiz 3