Confession of a Haskell Hacker


I have a confession to make. I recently released two Haskell packages, lens-family-core and lens-family based on my previous blog post and Edward Kmett’s blog post. However, I never tested this code before releasing it. By “never tested”, I mean that I am pretty sure that I never once executed any of this code. I did compile it many times, and I remember once I loaded the modules in ghci in order to type check some expressions to make sure my documentation about the composition laws were correct, but I think that is it.

Worse yet, when I wrote the focus function, I actually had no idea how the function worked. I simply wrote a function that matched the required type. My original definition was the following.

focus l m = StateT $ unwrapMonad . getCompose . l (Compose . WrapMonad . (runStateT m))

All the functions used in this definition are simply newType wrappers and unwrappers that get compiled away. I figured that this code was so simple that it could not be wrong. I have never run it to find out for sure.

Now to be fair, this is a simple library and, more importantly, it is an extremely generic library. The types are so polymorphic that I conjecture that there is only one way to write functions matching the required types such that all parameters are used non-trivially and recursion is not used. Furthermore, the interface for this library is based off of the existing data-lens library.

I am not going to argue whether it is good or bad that I have never tested this code. I am just stating for the record that this is the case.




Russell O’Connor: contact me