[Haskell-cafe] advice on a parsing function

Manlio Perillo manlio_perillo at libero.it
Wed Mar 11 13:59:25 EDT 2009


minh thu ha scritto:
> [...]
> The approach I suggested is a bit overkill. You can indeed use L.lines
> to split the input into lines then work on that.
> 
> But still, avoid the pair (Int, Bytestring). Instead, you can basically map
> on each line the unsafeReadInt modified to :
> - return the id
> - return if it is one kind of id or the other kind.
> 
> so :
> type UserId = Int
> type MovieId = Int
> unsafeReadInt :: Line -> Either MovieId UserId
> 
> Now you have a nice list [Either MovieId UserId] that
> you need to transform into (MovieId, [UserId]).
> 

Thanks, this seems a much better solution.


Manlio


More information about the Haskell-Cafe mailing list