Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

For reading line by line from stdin you can do something like

    import qualified Data.Text as T
    import qualified Data.Text.IO as T
    ...
    -- maybe you're reading things into a Set or something named acc
    go acc = do
      eof <- isEOF
      if eof then pure acc
      else do 
        line <- T.getLine
        T.putStrLn ("LINE IS "<>line)
        go (insert line acc)
There's hGetLine, hPutStrLn and hIsEOF for file handles, use withFile https://hackage.haskell.org/package/base-4.19.1.0/docs/Syste... which will close the handle when you exit the block. There are many more ways of doing this stuff of course, but the above will work fine for most stuff without any special libraries.

In general, use Data.Text for anything that you don't consider binary data (human-readable text as well as code, config files and such). Use Data.ByteString if you're thinking of it as pure encoded bytes.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: