3 ms·
> You also can't have methods that set local variables in the caller... How would you do that using ADTs?
by azth 12y ago
> You also can't have methods that set local variables in the caller...
How would you do that using ADTs?
- pcwalton 12y agoYou don't use methods, but instead switch on the discriminant of the ADT and take different actions (such as updating local variables). This is pretty related to the so-called expression problem. OO-style methods are good at extensibility, but they're bad at adding extension points (method calls), since you have to update every one and calls are limited in expressive power compared to the body of a switch statement. Functional-style ADTs are bad at extensibility (adding a new type requires updating all pattern matches), but they're good at adding new extension points, since you don't have to touch the data types and pattern matching is powerful. Supporting both styles in a language gives programmers the freedom to choose the best one for the task at hand.
- azth 12y agoMakes sense. Thanks.
- Manishearth 12y agoWith ADTs you would not have individual methods, but instead a match block possibly referencing the local variables.