[Haskell-cafe] source line annotations

Evan Laforge qdunkan at gmail.com
Fri Jan 28 18:01:39 CET 2011

On Fri, Jan 28, 2011 at 8:39 AM, Henning Thielemann
<lemming at henning-thielemann.de> wrote:
> Evan Laforge schrieb:
>> One of the first things I did when starting a larger haskell project
>> was to write a preprocessor that would replace certain tokens with
>> (token_srcpos (filename, func_name, lineno)) and then write x and
>> x_srcpos versions of the various 'throw' and logging functions.  This
>> is extremely handy to have, and since logs are part of my app's UI,
>> it's part of the app itself.
> I suspect that if you add source position information to 'throw' then
> you use 'throw' for showing (unintended) programming errors, but 'throw'
> is not intended for this purpose, but for expected problems like 'file
> not found' and so on. Adding source position to 'error', 'undefined',
> irrefutable patterns and logging functions for debugging makes sense to
> me, but for 'throw'?

When I say 'throw' I mean ErrorT.throwError, which boils down to
returning Left or Nothing.  I.e. expected errors, used simply for
early return.  And especially in the case of Nothing, when debugging
it's important to know which particular guard failed to make the
operation "expectedly" unexpectedly abort.  Otherwise I wind up
sticking 'trace's in strategic points to see where execution is going,
which is just a pain.

For the IO 'throw' srcpos info is just as important even if it's a
program crashing error, so I guess I disagree no matter which 'throw'
we're talking about.

More information about the Haskell-Cafe mailing list