[Haskell] ANNOUNCE: LocH, source locations in error, trace, and exceptions

Donald Bruce Stewart dons at cse.unsw.edu.au
Tue Nov 14 21:09:48 EST 2006

The topic of improving exception diagnosis in Haskell is hot at the
moment, and I'm pleased to announce the release of LocH, a small Haskell
module providing source location-specific error messages and debugging
strings for Haskell code. 

It uses the compiler-expanded 'assert' token, rather than cpp or m4, to
provide a lightweight approach to generating source locations. No
preprocessor is required. The code is available under a BSD license.

The LocH home:

The API:

Example usage:

    import Debug.Trace.Location

    main =
        trace assert "Starting ..." $ do
        print 1
        trace assert "Finished" $ do
        print 2
        let x = check assert $ head ([] :: [Int])
        print x

Will produce:

    $ ./a.out 
    A.hs:4:10-15: Starting ...
    A.hs:6:10-15: Finished
    a.out: A.hs:8:18-23: Prelude.head: empty list

LocH provides located versions of trace, failure, as well as check and checkIO
to wrap exception-throwing pure and IO code.

May all your exceptions be located,

More information about the Haskell mailing list