3 ms·
I think that "switch" doesn't name the feature properly. It's more about "pattern matching" as defined by functional languages such as Haskell or OCaml: http:/
by vog 14y ago
I think that "switch" doesn't name the feature properly. It's more about "pattern matching" as defined by functional languages such as Haskell or OCaml:
http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora016.html http://caml.inria.fr/pub/docs/oreilly-book/html/book-ora016....
This enables you to match any nested enum/tuple/list/tree structures, and have the compiler check that you didn't forget a case. The modern compilers can even give you an exact example of a case you forgot to specify.
Compared to those possibilities, the high-praised polymorphism of OO languages appears to be little more than simple dispatching. (At least for simple OO languages. There are also very powerful and expressive object systems such as CLOS.)