[Haskell-cafe] newbie questions (read, etc.,
666wman at gmail.com
Mon Oct 6 23:17:45 EDT 2008
the problem is that using readInt is actually _as slow_, at least using my
test script :-((
On Tue, Oct 7, 2008 at 5:12 AM, Don Stewart <dons at galois.com> wrote:
> > a slight modification to compile it :
> > change:
> > where sumFile = sum . map read . L.words
> > to :
> > where sumFile = sum . map (read . L.unpack) . L.words
> > but it's actually _slower_ than the non-bytestring version.
> Never unpack a bytestring.
> import qualified Data.ByteString.Lazy.Char8 as S
> main = print . go 0 =<< S.getContents
> go n s = case S.readInt s of
> Nothing -> n
> Just (k,t) -> go (n+k) (S.tail t)
> Assuming you're reading int, integers or doubles.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe