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 it works...

The recipe reads the file line by line. Each line is split into words using the function words. Since we are interested in only the host or its IP, we will take only the first word. Each host name / IP is considered as a tuple (hostname, 1), where 1 denotes that each entry corresponds to single access. We used the insertWith function to insert the preceding entry. If the entry already exists in the map, then we would use combining function to add 1 to the existing access count. We got hosts in the ascending order using the function toAscList. We used Control.Monad.forM_ to iterate over the list of accesses and print them to the console.

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