roc icon indicating copy to clipboard operation
roc copied to clipboard

Refinement of tag unions

Open ayazhafiz opened this issue 2 years ago • 2 comments

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!

ayazhafiz avatar Jun 03 '23 01:06 ayazhafiz

Is the notion link private? It redirects me to my notion home page.

osa1 avatar Jun 30 '24 11:06 osa1

Updated to https://github.com/roc-lang/rfcs/blob/main/0011-union-refinement.md

ayazhafiz avatar Jun 30 '24 15:06 ayazhafiz