2 ms·
That's one side of the expression problem; the other is adding a new operation. With dynamic dispatch, you can add new shapes without altering the others, but i
by gnuvince 4y ago
That's one side of the expression problem; the other is adding a new operation. With dynamic dispatch, you can add new shapes without altering the others, but if you want to add a new operation (e.g., perimeter()) then you have to modify the base class and all the children. With discriminated unions, adding a new shape requires modifying all the operations, but adding a new operation only requires the creation of a new function.
- t43562 4y agoIf adding an operation is the common case then optimise for that. If adding new shapes is the common case then ... You might feel that there are infinities of potential shapes out there but not really infinities of operations.