online advertising

Tuesday, June 2, 2015

Haskell 99 Problem 1

Problem:

Please find the problem here.

Solution:

Please see the solution as follow


The code needed some explanation. First unit test does not support error nicely, so instead of having the code throws error - it is easier to return a Maybe a instead. That's why I used myLastTest to return a Maybe a and unit tested that one. The public one used to fit the problem specification is simply a wrapper on top of it.

Next, the unit test derived assertEqual to assertEqualMaybeInt, this is a workaround that if I used assertEqual "" Nothing Nothing, that will not work because Haskell don't know how to show a Nothing (which has type Maybe a, with a unknown)

No comments :

Post a Comment