Is it possible in haskell to match complex patterns?
I mean, I have a Comma Separater Values (CSV) file:
name,ID,fieldA,fieldB
is it possible to write a function like:
getName (n:',':xs) = n
where n is not a single element but a list?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You should write a function to split your line…
Then you can write your accessor functions easily:
But as always it would be nice to use a data type:
Of course, if you need error handling, it gets a little bit more difficult…
BTW, there is a Haskell CSV lib out there: http://hackage.haskell.org/packages/archive/csv/0.1.1/doc/html/Text-CSV.html