SML/NJ incomplete match

Posted by dimvar on Stack Overflow See other posts from Stack Overflow or by dimvar
Published on 2010-04-04T15:27:15Z Indexed on 2010/04/04 15:33 UTC
Read the original article Hit count: 344

Filed under:

I wonder how people handle nonexhaustive match warnings in the SML/NJ compiler. For example, I may define a datatype

datatype DT = FOO of int | BAR of string

and then have a function that I know only takes FOOs

fun baz (FOO n) = n + 1

The compiler will give a warning

stdIn:1.5-1.24 Warning: match nonexhaustive FOO n => ...

val baz = fn : DT -> int

I don't wanna see warnings for incomplete matches I did on purpose, because then I have to scan through the output to find a warning that might actually be a bug. I can write the function like this

fun baz (FOO n) = n + 1 | baz _ = raise Fail "baz"

but this clutters the code. What do people usually do in this situation?

© Stack Overflow or respective owner

Related posts about sml