
Thanks to people who discussed the question of "who said `fromJust Nothing'" and -xc option. My last impression is that instead of using -xc it is better to write programs in a debug-friendly style. For example, let g x must return (Just _), but the programmer is not 100% sure that g x is free of bugs. Then, instead of f x = h $ fromJust $ g x one needs too write f x = case g x of Just y -> h y _ -> error $ concat ["Foo.f ", shows x "\n:\nImpossible happened:\n", "g ", shows x " = Nothing.\n" ] ----------------- Serge Mechveliani mechvel@botik.ru

Hi
My last impression is that instead of using -xc it is better to write programs in a debug-friendly style. For example, let g x must return (Just _), but the programmer is not 100% sure that g x is free of bugs. Then, instead of f x = h $ fromJust $ g x one needs too write
There are lots of solutions I use, all of which I think are nicer than your one! Use a safe module: http://neilmitchell.blogspot.com/2006/11/library-idea-safe-library.html - always works, a little bit of effort (I have such a module in my code). You then get: f x = h $ fromJustNote "Foo.f" $ g x Use Hat: http://haskell.org/hat - sometimes works Use Catch to prove the absence of pattern match errors: http://www-users.cs.york.ac.uk/~ndm/projects/catch.php - I'd say this is still too immature for anyone but me to use, but it can be useful. Use Yhi-stack - still unreleased, but gives out a stack trace on crashing. I am trying to push for this to be released soon! Thanks Neil

Both of these messages (from Neil and Serge) suggest use debugging ideas. Would anyone like to add them to http://haskell.org/haskellwiki/Debugging Simon | Use a safe module: | http://neilmitchell.blogspot.com/2006/11/library-idea-safe-library.html | - always works, a little bit of effort (I have such a module in my | code). You then get: | | f x = h $ fromJustNote "Foo.f" $ g x | | Use Hat: http://haskell.org/hat - sometimes works | | Use Catch to prove the absence of pattern match errors: | http://www-users.cs.york.ac.uk/~ndm/projects/catch.php - I'd say this | is still too immature for anyone but me to use, but it can be useful. | | Use Yhi-stack - still unreleased, but gives out a stack trace on | crashing. I am trying to push for this to be released soon! | | Thanks | | More about finding the source of fromJust Nothing. | | For g n = fromJust $ f n, | | ghc-6.6 often looses the reference to f in its run-time error | report -- when f returns Nothing. | And this is difficult to locate the source. | But one could write | g n = let Just m = f n in m, | | for which GHC reports | Main: M1.hs:9:11-22: | Irrefutable pattern failed for pattern Data.Maybe.Just m | | -- it points to the source line!

On Tue, Nov 14, 2006 at 05:28:22PM +0000, Simon Peyton-Jones wrote:
Both of these messages (from Neil and Serge) suggest use debugging ideas. Would anyone like to add them to http://haskell.org/haskellwiki/Debugging [..]
How can I put it there? It needs login. I do not know, whether my idea worths it, but, for any occasion, here is its new formulation ----------------------------------------------------------- Maybe, the simplest way to provide locating in the source code a mismatch run-time error in the library functions head, tail, fromJust, and such, is to avoid these functions and to use explicit matching instead. For example, for the program g x = h $ fromJust $ f x, ghc-6.6 often looses the reference to g, f, and h in its run-time error report -- when f returns Nothing. But for the program g x = let Just y = f x in h y, the ghc run-time report is like this: Main: M1.hs:9:11-22: Irrefutable pattern failed for pattern Data.Maybe.Just y -- it points to the source line! ---------------------------------------------------------------------- ----------------- Serge Mechveliani mechvel@botik.ru

ndmitchell:
Hi
My last impression is that instead of using -xc it is better to write programs in a debug-friendly style. For example, let g x must return (Just _), but the programmer is not 100% sure that g x is free of bugs. Then, instead of f x = h $ fromJust $ g x one needs too write
There are lots of solutions I use, all of which I think are nicer than your one!
Use a safe module: http://neilmitchell.blogspot.com/2006/11/library-idea-safe-library.html - always works, a little bit of effort (I have such a module in my code). You then get:
f x = h $ fromJustNote "Foo.f" $ g x
On a similar note, LocH would have: $ ./a.out a.out: A.hs:12:20-25: Maybe.fromJust: Nothing Given: 01 import Debug.Trace.Location 02 import qualified Data.Map as M 03 import Data.Maybe 04 05 main = do print f 06 07 f = let m = M.fromList 08 [(1,"1") 09 ,(2,"2") 10 ,(3,"3")] 11 s = M.lookup 4 m 12 in fromJustSafe assert s 13 14 fromJustSafe a s = check a (fromJust s) So there's lots of solutions now! -- Don

On 2006-11-14 at 13:57+0300 "Serge D. Mechveliani" wrote:
Thanks to people who discussed the question of "who said `fromJust Nothing'" and -xc option.
My last impression is that instead of using -xc it is better to write programs in a debug-friendly style. For example, let g x must return (Just _), but the programmer is not 100% sure that g x is free of bugs. Then, instead of f x = h $ fromJust $ g x one needs too write
f x = case g x of Just y -> h y _ -> error $ concat ["Foo.f ", shows x "\n:\nImpossible happened:\n", "g ", shows x " = Nothing.\n" ]
wouldn't f x = maybe mistake h (g x) where mistake = error $ ("Foo.f "++). shows x. (":\nThis shouldn't happen:\ng "++). shows x $ " = Nothing.\n" be slightly tidier? Jón -- Jón Fairbairn Jon.Fairbairn at cl.cam.ac.uk

On Tue, Nov 14, 2006 at 12:08:07PM +0000, Jon Fairbairn wrote:
[..] My last impression is that instead of using -xc it is better to write programs in a debug-friendly style. For example, let g x must return (Just _), but the programmer is not 100% sure that g x is free of bugs. Then, instead of f x = h $ fromJust $ g x one needs too write
f x = case g x of Just y -> h y _ -> error $ concat ["Foo.f ", shows x "\n:\nImpossible happened:\n", "g ", shows x " = Nothing.\n" ]
wouldn't
f x = maybe mistake h (g x)
where mistake = error $ ("Foo.f "++). shows x. (":\nThis shouldn't happen:\ng "++). shows x $ " = Nothing.\n"
be slightly tidier?
1) I do not see why the latter is tidier. It uses two extra functions. 2) By "needs to write" I meant "needs to write something like". ----------------- Serge Mechveliani mechvel@botik.ru
participants (5)
-
dons@cse.unsw.edu.au
-
Jon Fairbairn
-
Neil Mitchell
-
Serge D. Mechveliani
-
Simon Peyton-Jones