How to make Prelude.read: no parse more verbose ...

Hi,
I try to debug some existing Haskell-Code. Out of the blue I get a
'progname: Prelude.read: no parse'
error message from GHC.
Great.
Well, the code includes
# grep '\

On Dec 19, 2007, at 11:53 , Georg Sauthoff wrote:
I try to debug some existing Haskell-Code. Out of the blue I get a 'progname: Prelude.read: no parse' error message from GHC.
If you can install GHC 6.8.x, you can use ghci's interactive debugger. See http://cgi.cse.unsw.edu.au/~dons/blog/2007/11/14 for an example. -- brandon s. allbery [solaris,freebsd,perl,pugs,haskell] allbery@kf8nh.com system administrator [openafs,heimdal,too many hats] allbery@ece.cmu.edu electrical and computer engineering, carnegie mellon university KF8NH

Georg Sauthoff
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

Hi
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.
I use the Safe library to do this sort of stuff: http://www-users.cs.york.ac.uk/~ndm/safe/ You can call readMay to get a maybe result, or readNote which gives an augmented error message on a crash. You can of course combine this with the CPP trick: #define read readNote (__FILE__++":"++show __LINE__) Thanks Neil

Hello, You can also just use reads which returns a list of (partial) parses. -Jeff haskell-cafe-bounces@haskell.org wrote on 12/19/2007 03:17:39 PM:
Hi
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.
I use the Safe library to do this sort of stuff:
http://www-users.cs.york.ac.uk/~ndm/safe/
You can call readMay to get a maybe result, or readNote which gives an augmented error message on a crash. You can of course combine this with the CPP trick:
#define read readNote (__FILE__++":"++show __LINE__)
Thanks
Neil _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
--- This e-mail may contain confidential and/or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden.

Ketil Malde
Georg Sauthoff
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): [..]
Thanks! Indeed, it looks mean, but it helps, because I am currently using ghc < 6.8 ... Best regards Georg Sauthoff -- Fortune : 'Real programmers don't comment their code. It was hard to write, it should be hard to understand.' ;)

g_sauthoff:
Hi,
I try to debug some existing Haskell-Code. Out of the blue I get a 'progname: Prelude.read: no parse' error message from GHC.
Great.
Well, the code includes
# grep '\
' *| wc -l 23 (sic!) calls to the read fn.
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.
Really crazy would be the possibility to print out a backtrace, if some (library) function calls error ...
ghci now has a debugger that can backtrace like this, see this blog post for more details. http://cgi.cse.unsw.edu.au/~dons/blog/2007/11/14#no-exceptions using reads or even read lifted to a monad, like this, can be very useful, if it is code you control: readM :: (Monad m, Read a) => String -> m a readM s = case [x | (x,t) <- reads s, ("","") <- lex t] of [x] -> return x [] -> fail "readM: no parse" _ -> fail "readM: ambiguous parse" since you can handle failure without throwing an async exception. -- Don
participants (6)
-
Brandon S. Allbery KF8NH
-
Don Stewart
-
Georg Sauthoff
-
Jeff Polakow
-
Ketil Malde
-
Neil Mitchell