Tested : GHC 6.4.2, GHCi, Hugs 2005
This module provides a lightweight, pure Haskell mechanism to tag failures with the location of the failure call. The location message includes the file name, line and column numbers. All functions are passed the special symbol assert as an argument, which is expanded by the compiler into a location string.
failure assert "no such thing"
Also provided is a located trace for debugging purposes, and generic wrappers for pure and IO code, to tag location messages to exceptions:
check assert (head )
a.out: A.hs:18:10-15: Prelude.head: empty list
Or for IO functions:
do x <- checkIO assert $ readFile "/f"
$ ./a.out a.out: A.hs:18:20-25: /f: openFile: does not exist
While this code will run in Hugs, the Hugs assert token is not expanded usefully, producing:
Debug.Trace.Location> trace assert "works in hugs" (1+2) assertion works in hugs 3
|The assert token|
|A wrapper type for the assert token.|
|Location emitting errors|
failure assert "no such thing."
*** Exception: <interactive>:1:8-13: no such thing.
a.out: A.hs:18:12-17: no such thing.
A location-emitting trace call. It returns its third argument, emitting a located trace message to stderr as a side effect.
trace assert "made it here" (1+2)
<interactive>:1:21-26: made it here 3
check assert $ head 
*** Exception: <interactive>:1:6-11: Prelude.head: empty list
do x <- checkIO assert (readFile "/foo") x
"*** Exception: <interactive>:1:13-18: /foo: openFile: does not exist
|Produced by Haddock version 2.4.2|