これがエラーを引き起こしている理由を知っている人はいます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]
ご覧のとおり、いずれかのパラメーターが空であるか、ルックアップ関数に対して単に無効である可能性がある場合のケースを追加しようとしました。他に何がありますか?
また、yearIn
現時点では変数が冗長であることはわかっていますyearIn
。後でTotalPopリストの要素を取得するという意図した関数の使用に関連します。
与えられたすべての助けに前もって感謝します:)