[Haskell-cafe] How to make Prelude.read: no parse more verbose ...

Ketil Malde ketil+haskell at ii.uib.no
Wed Dec 19 14:50:23 EST 2007


Georg Sauthoff <g_sauthoff at web.de> writes:

> Well, how do I compile a Haskell program in such a way, that I
> get a useful error message from read? I mean, like the
> filename/linenumber of the calling expression for starters.

It's dirty, it's mean, but you can use CPP.  (On one line, and with
ghc -cpp):

#define read (\s -> case [ x | (x,t) <- reads s, ("","") <- lex t] of
 { [x] -> x ; 
   [] -> error("read: no parse at "++__FILE__++":"++show __LINE__); 
   _ -> error("read: no parse at "++__FILE__++":"++show __LINE__)})

-k
-- 
If I haven't seen further, it is by standing in the footprints of giants


More information about the Haskell-Cafe mailing list