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 log-parser with the simple Stack template:
        stack new log-parser simple
  1. Open log-parser.cabal and add the library containers as a dependent library in the subsection build-depends of the section executable:
        executable log-parser
        hs-source-dirs:      src
        main-is:             Main.hs
        default-language:    Haskell2010
        build-depends:       base >= 4.7 && < 5
                     , containers
  1. Open src/Main.hs and edit it. We will add log parsing and analysis here:
        module Main where
  1. Import modules for file IO and the strict map:
        import System.IO
        import qualified Data.Map.Strict as M
        import System.Environment
        import Control.Monad
  1. Read the file line by line:
 hLines :: Handle -> IO [String] hLines h = do isEOF <- hIsEOF h if isEOF then return [] ...

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