Code based on the book/site Learn You a Haskell for Great Good!