[Haskell-beginners] exceptions and stacks

Karol Samborski edv.karol at gmail.com
Wed Nov 7 08:51:03 CET 2012


Hi Emmanuel!

Have you looked at
http://hackage.haskell.org/packages/archive/loch-th/0.2.1/doc/html/Debug-Trace-LocationTH.html
? With the loch-th package you can write your own head function like
this:

{-# LANGUAGE TemplateHaskell #-}
module Main where

import Debug.Trace.LocationTH

myHead a = $check $ head a

and then something like myHead ([] :: [Char]) will print something like this:
test: test.hs:21:12-17: Prelude.head: empty list

In docs there is another useful function $failure that is "a
location-emitting error call".

Hope that helps.



More information about the Beginners mailing list