[Haskell-cafe] Specify compile error

Aleksandar Dimitrov aleks.dimitrov at googlemail.com
Thu May 3 18:14:22 CEST 2012

On Thu, May 3, 2012 at 5:36 PM, Ismael Figueroa Palet
<ifigueroap at 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.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120503/1bfee209/attachment.htm>

More information about the Haskell-Cafe mailing list