I'm trying to write a function which gives me the distance between every district in my list. The function distance gives me the distance between two districts as an Int from a set array, and I want to run through the whole list to sum up the distance between every district and its follower in the list.
But I'm getting the
Non-exhaustive patterns
error message. What have I overlooked? The function distance is working as it should.
lengthr :: [district] -> Int
lengthr [] = 0
lengthr (a:b:as) = (distance a b) + lengthr (b:as)
I added the line
lengthr [a] = 0to my code, to cover up the case of only one element left, and now the code works as intended!