If someone could lend a hand fixing this error, it would be much appreciated. The code is:
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 -> Int
getCityPopulation cs nameIn yearIn = head ([ z !! (yearIn - 1) | (x,z) <- lookup nameIn cs])
Expected behaviour:
getCityPopulation testData "New York City" 2
>>> 4
Actual behaviour:
• Couldn't match expected type ‘[(a0, [Int])]’
with actual type ‘Maybe (Coordinates, TotalPop)’
• In the expression: lookup nameIn cs
In a stmt of a list comprehension: (x, z) <- lookup nameIn cs
In the first argument of ‘head’, namely
‘([z !! (yearIn - 1) | (x, z) <- lookup nameIn cs])’
|
55 | getCityPopulation cs nameIn yearIn = head ([ z !! (yearIn - 1) | (x,z) <- lookup nameIn cs])
| ^^^^^^^^^^^^^^^^