[Haskell-beginners] Re: text file to data type

Patrick LeBoutillier patrick.leboutillier at gmail.com
Tue Dec 8 09:38:43 EST 2009


Hi all,

On Tue, Dec 8, 2009 at 5:29 AM, Heinrich Apfelmus
<apfelmus at quantentunnel.de> wrote:
> Joe Fredette wrote:
>> My suggestion would be to look into writing a parser (via parsec) to
>> handle this. Parsec is fairly easy to learn, and since your data is a
>> pretty simple format, the parser won't be hard to write.
>
> While I'm all for using a proper parser, Brent Pedersen notes that his
> data will have millions of rows, so that Parsec is likely to run into
> memory problems.
>
> I think something along the lines of
>
>   import Data.ByteString.Lazy.Char8 as B
>
>   parse = map (zipWith ($) formats . B.split '\t') . B.lines
>       where
>       formats = [str, str, int, int, int, int, int,
>                  int, int, float, float]
>       int   = fst . fromJust . readInt
>       float = \s -> read (unpack s) :: Double
>       str   = id
>

I've been looking at this example and I can't figure it out how it works.
Seems to me that "formats" is a list of functions that return different types.
How does this work?

Patrick


> will do just fine. (The implementation of  float  is a kludge, I think
> there's something on hackage for that, though?)
>
>
> Regards,
> Heinrich Apfelmus
>
> --
> http://apfelmus.nfshost.com
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



-- 
=====================
Patrick LeBoutillier
Rosemère, Québec, Canada


More information about the Beginners mailing list