[Haskell-cafe] newbie questions (read, etc.,
dons at galois.com
Mon Oct 6 23:12:23 EDT 2008
> a slight modification to compile it :
> 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.
More information about the Haskell-Cafe