On Thu, May 3, 2012 at 5:36 PM, Ismael Figueroa Palet <ifigueroap@gmail.com> wrote:
Hi, I'm writing a program like this:

data B = B Int
data A = Safe Int | Unsafe Int

createB :: A -> B
createB (Safe i) = B i
createB (Unsafe i) = error "This is not allowed"

Unfortunately, the situation when createB is called with an Unsafe value is only checked at runtime. 
If I omit the second case, it is not an error to not be exhaustive :-(

It is a warning at least, if you use the appropriate -W flag, or -Wall. You can combine it with -Werror to make it a compile-time error to omit cases in a pattern match (and other warnings.)

I'm not quite sure what your intention with the A data type is. createB could also have the signature A -> Maybe B, so the caller might check the outcome instead of having the entire program crash.

Cheers,
Aleks