- Create a new project io-monad with the simple Stack template:
stack new io-monad simple
- Open src/Main.hs; we will be editing this file.
- 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)
- 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 ...