[Haskell-cafe] Re: Debugging partial functions by the rules
Simon Peyton-Jones
simonpj at microsoft.com
Wed Nov 15 04:04:01 EST 2006
| > The fromJust and `head of empty list' errors are totally equivalent to
| > the dereferencing of zero pointer in C++ or NullPointerException in
| > Java. It pains me to see that exactly the same problem arises in
| > Haskell -- keeping in mind that already in C++ and Java one may
| > exterminate these errors given right encapsulations. Languages like
| > Cyclone or Cw use the type system to eliminate such errors. Surely
| > Haskell can do something about this?
|
| Yes, these techniques are fairly well known now, and hopefully some of
| the more experienced Haskellers are using them (I certainly use the
| non-empty list tricks). Any anyone with more than 6 months Haskell knows
| to avoid fromJust.
|
| The problem I see is that head/fromJust errors are usually caused by
| *beginner* Haskellers, who don't know the techniques for statically
| avoiding them.
I don't agree. My programs have invariants that I can't always express in a way that the type system can understand. E.g. I know that a variable is in scope, so searching for it in an environment can't fail:
head [ v | (n,v) <- env, n==target ]
(Maybe if I had an Oleg implant I could express all this in the type system -- but I don't.)
But yes, we should have more sophisticated techniques to express and check these invariants. With Dana Xu I'm working on this very thing (see her Haskell Workshop paper http://www.cl.cam.ac.uk/~nx200/research/escH-hw.ps); and Neil Mitchell is doing complementary work at York. So I think there is reason to be hopeful.
Simon
More information about the Haskell-Cafe
mailing list