No supported expression-level way to read or compare a sum's tag #74
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
matchis currently the only sum-aware form, and it is a statement: it cannot be used as an initializer, an argument, or aniftest (match is a statement, and has no value, seetests/encapsulation.scm). A simple tag check therefore has to go through the generated representation.A sum compiles to a struct with a
tagfield and generated enum constants:That has several problems:
tagis an implementation field, not documented syntax.shapeǂcircleis a generated name;ǂis an internal separator, not something users should have to type.It would be useful to have a supported expression-level way to read or compare a tag, for example:
or generated per-sum predicates such as
(shape/circle? s).Requirements:
match;p : (* shape)), like.;ǂor other generated names in user code;pub/imported sums;matchshould remain the exhaustive destructuring form. Makingmatchan expression is another possible direction, but this issue is about the smaller tag-only case.