Haskell - getting my feet wet

by Gregor Uhlenheuer on October 28, 2011

This time it’s Haskell - I bought myself a copy of the great book “Real World Haskell” by Bryan O’Sullivan, John Goerzen and Don Stewart. Now I am just working my way through the chapters and trying to practice along the exercises.

The first one is a simple function that calculates the lengths of a given list. As far as I can see this function behaves pretty much the same like the in-built length function.

The second one is supposed to calculate the mean of the elements in the given list. My first approach used a self-written sum function using foldr. Later I noticed that there is an in-built function called sum already that I can use.

The next two ones are about palindrome numbers or collections. The first one returns a palindrome list by simply appending the reverse of the input list.

The second function determines if the given list is palindromic by sequencially comparing the mirrored element pairs of the list.

Those functions do look really stupid simple but for an absolute beginner in Haskell it was kind of a hassle especially to get all those types right.

But nevertheless it’s quite interesting to slowly get a feel for those functional programming constructs. Also it makes fun to see that you are indeed able to solve these problems in the end after trying dozens of wrong approaches.

This post is tagged with programming and haskell