Reading numbers from a file with lazy ByteString This is my code for lazily reading a very large file which contains numbers separated by a new line character. Is there a way to simplify this using the ByteString module or would I have to use Data.Text

import Data.ByteString.Lazy.Char8 as L
main = do
  contents &lt;- L.getContents
  print (sumFile contents)
     where sumFile x = sum $ Prelude.map tups $ Prelude.map L.readInt (L.words x)
         where read' = tups.(L.readInt)


tups :: (Num a) =&gt; (Maybe (a, b)) -&gt; a
tups (Just (a,b)) = a
tups Nothing = 0
Here are some notes.


bytestring's documentation clearly states that:



  This module is intended to be imported qualified, to avoid name clashes with Prelude functions. eg.
  
  import qualified Data.ByteString.Lazy.Char8 as C


This lets you unambiguously write map without Prelude qualifier.


There are some properties of map that allow you to write map f . map g as map (f.g).
tups can be rewritten as one-liner with maybe and fst

tups = maybe 0 fst


All of this leads to following code:

import qualified Data.ByteString.Lazy.Char8 as L
main = L.getContents &gt;&gt;= print . sum . map (maybe 0 fst . L.readInt) . L.words