O'Reilly logo

Haskell Cookbook by Yogesh Sajanikar

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Create a new project io-monad with the simple Stack template:
        stack new io-monad simple
  1. Open src/Main.hs; we will be editing this file.
  1. After initial module definition, add the following imports. Only those functions that are used in the program are imported from the corresponding module:
        import System.IO (hGetLine, hIsEOF, withFile, Handle,         IOMode(..))        import System.Environment (getArgs)        import Control.Monad        import Data.List (intercalate)
  1. Write the function getLineSeq, which returns a list of lines when given a file handle:
         -- From the file handle, check if we have reached end of file,         -- otherwise read the file line by line         getLinesSeq :: Handle -> IO [String]         getLinesSeq h = do         eof <- hIsEOF h -- Use (:) to ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required