roc icon indicating copy to clipboard operation
roc copied to clipboard

Pattern matching on qualified constants

Open rtfeldman opened this issue 3 years ago • 1 comments

It should be possible to do this:

when x == 1 is
    Bool.true -> ...
    Bool.false -> ...

This would also allow for pattern matching on other constants, e.g. numbers or other opaque tags besides Bool.

rtfeldman avatar Oct 02 '22 22:10 rtfeldman

I think we may have discussed this before, but I believe this would make it possible to induce breaking changes without changing API surfaces. For example if I have

# Status.roc
Status := [Success, Failure]

success = @Status Success
failure = @Status Failure

# App.roc
when status is
  Status.success -> ...
  Status.failure -> ...

and now Status gets updated to

Status := [Success, Failure, Pending]

then App.roc is now broken, because the API surface of Status is leaked through the pattern match, even though you would not expect this to be a breaking change.

ayazhafiz avatar Oct 02 '22 23:10 ayazhafiz