Book Image

Haskell Cookbook

Book Image

Haskell Cookbook

Overview of this book

Haskell is a purely functional language that has the great ability to develop large and difficult, but easily maintainable software. Haskell Cookbook provides recipes that start by illustrating the principles of functional programming in Haskell, and then gradually build up your expertise in creating industrial-strength programs to accomplish any goal. The book covers topics such as Functors, Applicatives, Monads, and Transformers. You will learn various ways to handle state in your application and explore advanced topics such as Generalized Algebraic Data Types, higher kind types, existential types, and type families. The book will discuss the association of lenses with type classes such as Functor, Foldable, and Traversable to help you manage deep data structures. With the help of the wide selection of examples in this book, you will be able to upgrade your Haskell programming skills and develop scalable software idiomatically.
Table of Contents (13 chapters)

Log analysis with map

In this recipe, we will use map to analyze the access log for the Apache web server. The log contains access parameters for each host accessing the web server per line. The log looks like this:

    64.242.88.10 - - [07/Mar/2004:16:10:02 -0800] "GET
/mailman/listinfo/hsdivision HTTP/1.1" 200 6291 64.242.88.10 - - [07/Mar/2004:16:11:58 -0800] "GET
/twiki/bin/view/TWiki/WikiSyntax HTTP/1.1" 200 7352 64.242.88.10 - - [07/Mar/2004:16:20:55 -0800] "GET
/twiki/bin/view/Main/DCCAndPostFix HTTP/1.1" 200
5253

The line starts with hostname or IP that is accessing the web server. The remaining part of the line includes date and time, method of access (GET, PUT, POST, and so on), and the path of the web server being accessed. The server also prints status information.

...