AboutLocH is 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. Exampleimport Control.Monad.State import Debug.Trace.Location main = trace assert "Starting runState" $ do runStateT code [1..] >> return () trace assert "Finished" $ do let x = 1 + 2 failure assert "All dead now." code = do x <- pop io $ print x io $ checkIO assert (readFile "/tmp/f") y <- pop io $ print y return () pop = do check assert (head []) (x:xs) <- get put xs return x io = liftIO Produces:
$ ./a.out
A.hs:5:10-15: Starting runState
a.out: A.hs:20:10-15: Prelude.head: empty list
Indicating that the use of 'head' on line 20 failed. Locating errors mechanicallyLocH also comes with a preprocessor, that can be used to insert located errors automatically. Given a program failing with 'fromJust: Nothing':
$ ghc A.hs --make -no-recomp
[1 of 1] Compiling Main ( A.hs, A.o )
Linking A ...
$ ./A
A: Maybe.fromJust: Nothing
To locate the error all we have to do is "import Debug.Trace.Location", and then recompile the source with the 'loch' preprocessor:
$ ghc A.hs --make -pgmF loch -F -no-recomp
[1 of 1] Compiling Main ( A.hs, A.o )
Linking A ...
$ ./A
A: A.hs:14:14-19: Maybe.fromJust: Nothing
DocumentationGet LocH
Project Activity
|