[Haskell-beginners] Non-exhaustive case leads to runtime error?

Rafal Kolanski rafalk at cse.unsw.edu.au
Tue Sep 9 16:19:09 EDT 2008


Greetings,

I just ran into the following situation in an IO do block:
         case msel of Just sel -> do toggleFretArea selectionRef sel
                                     widgetQueueDraw canvas
                      Nothing -> return ()
except I omitted the last line. I expected the compiler to complain, but 
it silently compiled it, and I got a runtime exception when the program 
ran instead.

Is this behaviour intentional? Can I get ghc to warn me about it anyway 
(something like -Wall)?

Two more guiding questions:
1. What is a good idiom for "In this case do blah otherwise don't do 
anything"?
2. Is there a shorter way of writing a no-op in a do block than "return ()"?

Thanks in advance!

Rafal Kolanski.


More information about the Beginners mailing list