[Haskell-cafe] Re: Debugging partial functions by the rules

Daniel McAllansmith dm.maillists at gmail.com
Fri Nov 17 19:37:30 EST 2006

On Saturday 18 November 2006 00:37, Neil Mitchell wrote:
> Hi
> > > How controversial would a proposal to {-# DEPRECATE fromJust #-} be, in
> > > favour of:
> > >
> > >     Just _ = x  -- which will give you the precise line number
> > >
> > > It seems to me this is one cause of mysterious newbie errors we
> > > could easily discourage, with little harm.
> >
> > Btw, I'm not seriously suggesting removing it ;)
> > It could be discouraged ever so slightly in the haddocks though.
> I strongly disagree. If we are removing things that confuse newbies
> why not start with higher rank types, MPTC's and GADT's ;)
> fromJust is simple, useful and clear. What you mean is that
> implementations aren't very good at debugging this. It seems unfair to
> blame partial functions for the lack of a debugger. If a call stack
> was automatically output every time a fromJust failed would this even
> be something people complained about?

Well, I strongly disagree. :)

I suspect I would be classified as a newbie relative to most posters on this 
list but here's my thoughts anyway...

I chose to learn haskell largely because I thought the static type safety 
would help eliminate bugs, I've never once been happy when I've needed to 
fire up a debugger or add trace statements and I hoped they would become 
things of the past.

One of my initial responses to haskell was disappointment upon seeing head, 
fromJust and the like.  'Those look nasty', I sez to meself.
From day one I've tried to avoid using them.  Very occasionally I do use them 
in the heat of the moment, but it makes me feel unclean and I end up having 
to take my keyboard into the bathroom for a good scrubbing with the sandsoap.

The disappointment has pretty much changed to frustration since reading Oleg, 
and others, type-hackery work.  I realise the problems are just poor/limited 
usage of haskell, not inherent in the language.  Unfortunately I can 
understand the 'right' solutions but still have trouble formulating them 
myself.  I'm hoping that if I hang out in the type-hackery 'hot zone' long 
enough I'll start emitting enough picoOlegs myself to solve simple 
problems. ;)

My view is that if I can reason about my program and know a static property I 
want to be able to stamp this into the types and have my reasoning validated 
during compilation.  
But existing library code with weak typesafety is a large inertial mass, when 
trying to do something 'right' the interfacing is a daunting prospect.

In general I'd rather have effort go into promoting 'right' solutions, and 
making those solutions easier to express, than going into debuggers 
for 'wrong' solutions.


More information about the Haskell-Cafe mailing list