Tuesday, June 2, 2015

Haskell 99 Problems

Problem:

Please find all the problem here.

Solution:

In this post, we start with the design of the test harness. Remember in the old days I made a project for each Project Euler problem - once it scales, there are something a hundred executable files. It is taking significant amount of space and hard to clean up there.

Haskell problems don't have this problem. As a matter of fact, as we are simply doing programming exercise, I don't even bother to compile them. They could be compiled, but why would I wanted to do that?

One might also ask - why bother writing about your own programming exercises? If I have learnt a lesson - time educated me that non-trivial code really needs documentation. It is hard to read, even my own code, after some times like a couple years, so better document now (right after writing code, sometimes even before)

So, let's get back to the test harness. Haskell code can be executed in GHCi, initially, I thought it is okay to just capture standard I/O and error of GHCi by piping file in and out, it worked, but less professional. I used HUnit instead.

A typical problem look like follow:

Most readers are probably like me, who is not familiar with Haskell. The code needed some explanations. First, to allow one file references another file, that file need to be a module. Second, a module's file name must match the file's name. The rest of the code is pretty trivial, of course, one need to learn Haskell to read the code. The module concept tripped me up, so I decided to write about it. If you knew Haskell, that is pretty trivial too.

I am learning Haskell through learn you a Haskell, this is a great resource, but sadly without programming exercises, and that's why I am working on all these problems.

No comments :

Post a Comment