online advertising

Tuesday, June 2, 2015

Haskell 99 Problem 3


Please find the problem here.


Please see the solution as follow:

In this solution, I have a problem - using pattern matching alone, it is hard to differentiate the case where I have an empty list and at the same time the index is less than 0, and in that case I wanted to output a the not supported message instead of the element not found one.

To that end, I simply used a helper function. I could have used a nested if expression instead, but Haskell is all about elegant code and clarity, so I chose to use helper function instead.

Now the wrapper function a simple condition, therefore I can use guard expression instead of an if statement!

No comments :

Post a Comment