[Haskell-cafe] advice on a parsing function

minh thu noteed at gmail.com
Wed Mar 11 13:29:26 EDT 2009

2009/3/11 Manlio Perillo <manlio_perillo at libero.it>:
> minh thu ha scritto:
>> [...]
>> I suggest you try an alternative strategy.
>> That altenrative strategy is twofold, just like you have
>> quiz' and quiz'.
>> This alternate strategy avoid pattern matching on strings
>> (which would be cumbersome for a bit more complex syntax).
> But for this specific case it is very compact and elegant (IMHO).

I would say it is difficult to see what you're doing in the code without
the desciption you gave in the mail. But you're right, it's not the string
pattern matching which is the problem.

It is more the pair (Int, rest of the bytestring which can begin or
not with ':')...

Why not have quiz' accepting just the bytestring (and not the id value),
and returning the (Int,[Int]) ?

>> [...]
>> Now, given those two functions, try to apply them
>> on your input string, feeding the next function application
>> with the resulting string of the current application.
> So, I should not split the string into lines?

See below.

> An useful feature of my program is that it parses both an input like:
> 1:
> 1046323,2005-12-19
> and
> 1:
> 1046323
> If I write a parser from scratch I need to implement two separate functions.

I didn't think to that but nothing prevent you to write the second function I
suggested to account for that case, or for an end of line (if can 'eat' the ':'
from the input, you can also eat a newline).


More information about the Haskell-Cafe mailing list