Refinement of tag unions
We'd like to implement Union Refinement, a proposal to bring flow-typing-style semantics to Roc. This feature would allow typing code like
canRoleDo : [User, Admin, SuperAdmin] -> Bool
canRoleDo = \role -> when role is
User -> ...
other ->
# here, `other` has type [Admin, SuperAdmin]
whereas the current implementation of Roc would type other as [User, Admin, SuperAdmin].
It's expected that this feature will provide a more natural feel to the behavior of tag unions, similar to how a developer may have experienced unions in other languages - particularly those with structural subtypes!
The full proposal and implementation description is provided in this document: https://github.com/roc-lang/rfcs/blob/main/0011-union-refinement.md. See also this Zulip ideas topic for discussion on the proposal: https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/Narrowing.20types.20in.20when.20expressions.
If you'd like to help out implementing this, please don't hesitate to reach out in the #contributing channel in the Roc Zulip!
Is the notion link private? It redirects me to my notion home page.
Updated to https://github.com/roc-lang/rfcs/blob/main/0011-union-refinement.md