Reputation: 507
Why binding not exhaustive
warning on the last line?
datatype fruit = Apple
datatype sizedFruit = Big of fruit | Small of fruit
val Big x = Big Apple;
I think the binding IS exhaustive because the RHS expression matches the LHS pattern with x = Apple
on the one and only given case. Hence, could I safely ignore this warning?
The warning goes away by replacing line 2 with datatype sizedFruit = Big of fruit
, but my real use case can't afford this. Thanks in advance.
Compiler: Standard ML of New Jersey (64-bit) v110.96
Upvotes: 2
Views: 851
Reputation: 36098
The definition of exhaustiveness does not consider the RHS of a binding, only the pattern itself. Otherwise the definition would be much more complicated. In practice, that is good enough, because there isn't much reason to write bindings like the above instead of the simpler val x = Apple
. That is, you can take the warning as an indication of redundant code in this case. :)
So yes, you can ignore the warning. Or simplify the program.
Upvotes: 2