Dev Days: Learning Haskell

There is a strong culture of innovation at Caplin and everyone is encouraged to take time out to explore new technologies, build useful tools that would not otherwise be scheduled, and generally learn interesting things.

The easiest way to make this work is to stick a dev day in the calendar at regular intervals. Dev days are dedicated to exploring new ideas and technologies, learning new things and experimenting with tools that could ultimately benefit everyone.

I don’t really need a particular tool right now so I’m using my dev days to make myself smarter – a long time passion of mine. I’m learning Haskell, a lazy, purely functional programming language with a very terse syntax.
Here are some typical examples of the fun you can have with Haskell:

-- fibonnacci functions from
-- http://www.haskell.org/haskellwiki/The_Fibonacci_sequence
-- type class signature. Supports Integers of unbounded size
fib :: Integer -> Integer
-- basic definition using recursion and simple pattern matching
fib 0 = 0
fib 1 = 1
fib n = fib (n-1) + fib (n-2)
-- O(n) implementation using zipWith to lazily create an infinite list
fib n = fibs!!n
	where fibs = 0 : 1 : zipWith (+) fibs (tail fibs)
-- classic map function
map' :: (a -> b) -> [a] -> [b]
map' _ [] = []
map' f (x:xs) = f x : map' f xs

There is a web-based interpreter at Try Haskell that lets you play with the language without installing anything.

I started by going through Learn You a Haskell, a gentle introduction to the language, and am starting to progress on to some of the more complex features of the language. Unlike with certain other languages, I find the fundamental building blocks of Haskell to be very elegant and usable from the beginning. Maybe that’s my mathematical bias speaking, or perhaps I just appreciate functionally elegant simplicity.

It will be interesting to see just how close to true the claims of scalability and easy concurrency really are. I’ll find out the answer when I’ve learned enough to be dangerous – that’s the real turning point when learning any new technology.

Leave a Reply

Your e-mail address will not be published. Required fields are marked *