[Haskell-cafe] advice on a parsing function

Manlio Perillo manlio_perillo at libero.it
Wed Mar 11 14:37:26 EDT 2009


Manlio Perillo ha scritto:
> 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.
> 

Done:
http://hpaste.org/fastcgi/hpaste.fcgi/view?id=2309


real	1m15.220s
user	0m4.816s
sys	0m0.308s


3084 KB memory usage

Previous version required 4956 KB of memory.


Thanks again for the suggestion, Minh.


Manlio


More information about the Haskell-Cafe mailing list