Anyone know why this is causing the error Non-exhaustive patterns in function getCityPopulation
?
type Name = String
type Coordinates = (Int, Int)
type Pop = Int
type TotalPop = [Pop]
type City = (Name, (Coordinates, TotalPop))
testData :: [City]
testData = [("New York City", ((1,1), [5, 4, 3, 2])),
("Washingotn DC", ((3,3), [3, 2, 1, 1])),
("Los Angeles", ((2,2), [7, 7, 7, 5]))]
getCityPopulation :: [City] -> Name -> Int -> Maybe (Coordinates, TotalPop)
getCityPopulation [] nameIn yearIn = error "Can't be empty"
getCityPopulation [cs] nameIn yearIn
| nameIn == "" = error "Input City name"
| yearIn == 0 || yearIn < 0 = error "invalid year"
| otherwise = lookup nameIn [cs]
As you can see, I've tried to add a case for when any of the parameters may be empty or just invalid for the lookup function. What else could it be?
Also, I know the yearIn
variable is redundant at the moment, it will be pertinent later, for the intended function use, which will be to get the yearIn
element of the TotalPop list.
Thanks in advance for any and all help that is given :)