3 ms·
This is what I was talking about. With pattern matching I now expect this exact pattern will be 98% of usage of `sealed` anything. It would be nice to have some
by speed_spread 3y ago
This is what I was talking about. With pattern matching I now expect this exact pattern will be 98% of usage of `sealed` anything. It would be nice to have some sugar like
tagged-union Tree {
Leaf(int value),
Node(Tree left, Tree right)
}
I used `tagged-union` because for backward compat I think using `enum` would not be possible but really it could be anything.
- kaba0 3y agoWhile I agree that some syntax sugar would be welcome here (AFAIK the best you can currently do is sealed interface Tree permits Tree.Leaf, Tree.Node { record Leaf(int value) extends Tree {} record Node(..) extends Tree {} } ), it is not too terrible. Also note that rust really mixed up the nomenclature here with their enums, these were known in every language previously simply as ADTs. It makes sense for these to not have identity, while java enums are always a single instance.
- vips7L 3y agoYou want `implements Tree` here or this won't compile.