Skip to content

Instantly share code, notes, and snippets.

@ufcpp
Created February 2, 2015 15:52
Show Gist options
  • Select an option

  • Save ufcpp/71928d30896641df6939 to your computer and use it in GitHub Desktop.

Select an option

Save ufcpp/71928d30896641df6939 to your computer and use it in GitHub Desktop.
Completeness for type pattern matching
class Message { }
class A : Message { }
class B : Message { }
class C : Message { }
class PatternMatching
{
public static void Match(Message m)
{
if (m is A) { /* ... */ return; }
if (m is B) { /* ... */ return; }
if (m is C) { /* ... */ return; }
// もう所望の全パターン網羅済み!
// ここに来るはずがない!
// というか、ここに来ない保証がほしい。
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment