[Haskell] modern language design, stone age tools

Alastair Reid alastair at reid-hoffmann.net
Wed Jun 23 16:43:46 EDT 2004

On Wednesday 23 June 2004 20:38, S. Alexander Jacobson wrote:
> It would be really nice if you could pass an
> error message down to every function that might
> fail. e.g. using implicit parameters*:
>    myFunc 0 x = head x with ?failMsg="myfunc 0 caused the error"

Interesting.  Two variations on that:

1) Getting a 'stack' trace (i.e., a list of ancestors) can be more
   useful than just knowing the immediate ancestor so you might want
   myFunc to also take an implicit parameter and to add that 
   parameter to what it says:

     myFunc 0 x = head x 
      with ?failMsg="myfunc 0 caused the error but myFunc was called because "
                   ++ ?failMsg

   [I can't remember if with acts as a let or a letrec.  The intention is
    to use the ?failMsg passed implicitly to myFunc]

2) If you don't want to put errors in the type system, you could instead use
   exceptions something along the lines of:

      myFunc 0 x = mapException 
                     (\ err -> show err ++ "when invoked by myFunc 0")
                     (head x)

   [Not quite type correct but hopefully clear enough.  The idea is to combine
    the exception value returned with some extra information about the context
    with the idea that whoever called myFunc might add extra information.
    Ideally, the Exception type would be recursive so we could build chains of
    exceptions without having to use Show.]

Alastair Reid

More information about the Haskell mailing list