"...whose type indicates its state"<p>This is one of my favorite scenarios facilitated by static types. And one of the reasons I like languages with ML-like syntax for algebraic datatypes and pattern matching - this pattern is so easy to implement in them<p><a href="http://en.wikipedia.org/wiki/Algebraic_data_type" rel="nofollow">http://en.wikipedia.org/wiki/Algebraic_data_type</a><p>An concise example of the usage can be found in
<a href="http://queue.acm.org/detail.cfm?id=2038036" rel="nofollow">http://queue.acm.org/detail.cfm?id=2038036</a><p>(Section starting with the sentence "Consider as an example the following types for representing the state of a network
connection:")<p>That's in Ocaml but the same syntax applies more or less to all languages with ADT:s.
Ah, a clear instance of <a href="http://blogs.msdn.com/b/oldnewthing/archive/2011/01/26/10120297.aspx" rel="nofollow">http://blogs.msdn.com/b/oldnewthing/archive/2011/01/26/10120...</a>