I've hade some requests to explain some of the less common functions used in my log analysis screencast . I think the most straightforward approach is to examine each of the lines in a literate Haskell style. This is going to be a long-winded description of exactly what's going on. If you understood everything in the screencast, this post will probably bore you. But if you found yourself wondering what the heck was going on, this post might help. > :m + Data.List Data.Function > contents <- readFile "user.log" > let l = lines contents > let t = map words l > mapM print $ take 2 t These four lines are pretty straightforward. ":m +" is GHCi syntax that is similar to an import. readFile :: FilePath -> IO String reads the contents of a file into a string. The lines function splits the string on newlines and creates a list of strings representing each line in the file. We map the words function over each of these lines to split the
Showing posts from June, 2010
- Other Apps
Yesterday I released version 0.2 of the Heist XML templating library . This release makes some significant API changes, so it may break existing applications. But if you're only using Heist for basic templating, then you probably won't have to change anything. However, http://snapframework.com uses Heist extensively; and it did not require any code changes to upgrade. Here is a summary of what changed in 0.2: String substitution in attributes Support for DOCTYPE in templates New implementation for TemplateMonad Windows support Typeable instance Documentation improvements Bug fixes The biggest new feature in 0.2 is attribute string substitution. Because Heist's templating mechanism uses XML tags, it didn't automatically work for string substitution inside tag attributes. You don't have to do very much web development before you find yourself wanting this. Now you can get substitution in attributes using the syntax "$(name)". The Heist Tutori
- Other Apps
The other day I wanted to analyze some of my website log files to get a better idea of how many active users I have. I've been meaning to do this for quite some time, but have kept putting it off. I decided to see what I could accomplish by just doing some experimenting in GHCI. It was so easy and convenient that I decided to do a screencast demonstrating what I did and how easy it was. The conciseness of Haskell combined with the instant feedback of an interpreter make a very powerful combination. Here's the screencast on vimeo .