Getting real with Haskell

Yesterday I decided to leave the relative safety of solving exercises in tutorials and instead try solving a small problem I had at work. I had pairs of times (points in time, like Wednesday November 8 01:17) and I needed the difference between them. Not a tricky problem by any stretch of the imagination, but I figured I had to start using Haskell at some point. I might as well make this that point.

I started out by playing around with System.Time and System.Locale in gchi. One thing that seemed missing was a function that took a String and tried to interpret it as a CalendarTime. After a mail to Haskell Cafe I discovered MissingH.

I found myself programming top-down, stubbing “sub functions” while trying to get the types of the current function right. It turns out I was “lucky” and there wasn’t many monads involved, but still I did run into some problems with mixing do notation and let, where, and case. In the end I split out those constructs and kept only the most basic syntactical constructs inside the do.

Here’s the end result, not the most functional piece of Haskell code ever seen, but it’s the first time I dip my toes in the sea of Haskell without a tutorial life-west.

⟸ Epilicious in Ubuntu Edgy Eft Code commenting tool? ⟹

dons

Nice! Just put up a quick refactor/response over here.

Feel free to drop by #haskell

Magnus

Thanks, dons. I have to say your code is shorter, while still as easy to read as what I wrote (totally subjective comment, of course). Nice!

I’ve seen maybe in tutorials, but your code had me consulting Hoogle on either.

Leave a comment