[Haskell-beginners] exceptions and stacks

Emmanuel Touzery etouzery at gmail.com
Wed Nov 7 09:03:38 CET 2012


     that is very interesting.
     on top of that, this library also offers an "assert" function, 
which will throw an exception with location in the source code if the 
assert condition is false.

     so i will definitely consider this. i would really rather compiler 
support but... That's probably the next best thing.


On 7.11.2012 8:51, Karol Samborski wrote:
> 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