4 ms·
// By contrast, Rust (and I believe Haskell?) require exhaustive matching: let MyValue::String(ref s) = map[&200]; // Invalid! This is called irrefutable
by doomrobo 8y ago
// By contrast, Rust (and I believe Haskell?) require exhaustive matching:
let MyValue::String(ref s) = map[&200]; // Invalid!
This is called irrefutable pattern matching in Rust terminology. Haskell actually doesn't enforce this at compile time. Consider the program
data Foo = A Int | B Int
x :: Foo
x = A 10
-- Do an invalid pattern match
y :: Int
y = let (B i) = x in i
main :: IO ()
main = do
print y
This compiles without warning and gives the error at runtime:
foo: foo.hs:8:9-17: Irrefutable pattern failed for pattern B i