2 ms·
The visitor pattern essentially gives you pattern matching for your example. It can even give you destructuring pattern matching, if you wish. With a fixed hier
by Pyxl101 11y ago
The visitor pattern essentially gives you pattern matching for your example. It can even give you destructuring pattern matching, if you wish. With a fixed hierarchy, each visit method handles one concrete case, and its signature can destructure fields and pass them individually. It's a hoop to jump through but not so bad.
- twic 11y agoVery true, but you have to write it all by hand, so it's the usual tedious and error-prone boilerplate until IDEs learn to autogenerate it. It would be nice to have an automatic solution like you get with real ADTs.