I am trying to parse a record from a lists of lists (continuing from this question).
Here's my record
data Record = Record Text Text Text Text Text Text Text Text Text deriving (Show, Generic)
This syntax works:
parseRecords :: [[Text]] -> [Record]
parseRecords = map (\[f1,f2,f3,f4,f5,f6,f7,f8,f9,_] -> Record f1 f2 f3 f4 f5 f6 f7 f8 f9)
This syntax checks, but has me fixed at 10 parameters. I would rather be able to have more than that and ignore the ones greater by pattern matching them into a [_] list I will not pass along. I tried the following:
parseRecords = map (\f1:f2:f3:f4:f5:f6:f7:f8:f9:[_] -> Record f1 f2 f3 f4 f5 f6 f7 f8 f9)
This, however, fails with:
Parse error (line 27, column 24): parse error on input ‘:’
I could have sworn I saw this kind of pattern matching used in lambdas before. What am I missing that my colon operators are a parse error? It is hard to interrogate what's going wrong.
Thanks!
(\(f1:f2:f3:f4:f5:f6:f7:f8:f9:[_]) -> Record f1 f2 f3 f4 f5 f6 f7 f8 f9)[_]is also wrong, you want just_.[_]is a pattern matching a list with exactly one element in it.