Re: [Haskell-cafe] How to make Prelude.read: no parse more verbose ...
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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to make Prelude.read: no parse more verbose ...
Hello, You can also just use reads which returns a list of (partial) parses. -Jeff [EMAIL PROTECTED] 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.___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to make Prelude.read: no parse more verbose ...
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
Re: [Haskell-cafe] How to make Prelude.read: no parse more verbose ...
Georg Sauthoff <[EMAIL PROTECTED]> 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 ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
Re: [Haskell-cafe] How to make Prelude.read: no parse more verbose ...
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] [EMAIL PROTECTED] system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED] electrical and computer engineering, carnegie mellon universityKF8NH ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
[Haskell-cafe] 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 '\' *| 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 ... Best regards Georg -- Fortune : 'Real programmers don't comment their code. It was hard to write, it should be hard to understand.' ;) ___ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe