[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-02-28 (10:32) |
From: | Keith Wansbrough <Keith.Wansbrough@c...> |
Subject: | Re: [Caml-list] Fragile pattern matching?! |
Alex Baretta writes: > let to_int value = match value with > | Int x -> x > | _ -> raise Some_exception > > The compiler signals a warning for a fragile pattern matching at the "_" > character. > > Why in the world should this code signal such a warning? The reason is to do with code maintenance. When in future you add another constructor to the value type, the type checker will tell you the locations of all matches that have now become incomplete, so that you can fix them. But the match in "to_int" above will never become incomplete. If the type checker passed this silently, then a bug could easily be introduced. Hence the warning. HTH. --KW 8-)