Re:The Expression Problem and Tables
by sgreben on Monday April 20, 2015 @10:32AM
(#9408327)
Sum types + exhaustiveness checking already do this, right? For this example:
Compiling this yields:
just as we'd like.
[ Parent
| on HN ]
Adding new animals or actions requires access to and recompiling this code. The expression problem attempts to find a way around that.
I'm not proposing this as a solution to the expression problem (which has actual solutions, as noted in the other comments [0] and elsewhere [1]).
It is, however, an extremely simple way of implementing the table-style dispatch outlined in the post, with a reasonable layout and compile-time completeness checks.
It's not open to extension outside the compilation unit, but in exchange it is dead simple and you still only ever need to change exactly two places in the code if you want to extend along either axis. Sometimes you just don't need polymorphism when a switch statement will do.
[0] https://news.ycombinator.com/item?id=9409779 [1] (PDF) http://www.math.nagoya-u.ac.jp/~garrigue/papers/variant-reus...
Re:The Expression Problem and Tables
by Ono-Sendai on Monday April 20, 2015 @10:36AM
(#9408353)
The problem is not so much if the compiler will catch it, but how to lay out the new code/types in an editor, hopefully all in one place or accessible from one place.
C++ will catch a missing combination at compile time as well.