Tomasz Zielonka wrote:

On Tue, Nov 08, 2005 at 02:43:47PM +0000, Malcolm Wallace wrote:
Of course, there is the old stand-by C pre-processor trick:

   #define superError(s)  error (s++"\nin file "++__FILE__ \
                                 ++" at line "++__LINE__)

There is a nice trick I saw in darcs' code to make this even more
Haskellish:

   #define superError  (\s -> error (s++"\nin file "++ __FILE__ \
                           ++" at line "++ show (__LINE__ :: Int)))

so you can simply write:

   superError "message"
Don't you also need to define "head" as a CPP macro (otherwise you'll just get the location of "head",
and I'm sure you know where to find that already)?

#define head (\xs -> case xs of { (x:_) -> x ; _ -> superError "head: empty list"})

Unfortunately, I don't think CPP will play nicely with operators like ! :-(

There really should be a better way to do this, "head: empty list", "read: no parse" etc is high on my list of Haskell annoyances.

-k
_______________________________________________
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

Reply via email to