Stream: ideas

Topic: Namespaced tags


view this post on Zulip Matt Hunzinger (Aug 29 2023 at 10:38):

Hey everyone! Thanks so much for making roc, this looks like an incredible language :heart:

My main concern is that tagged effects being used like strings will have a lot of downsides. For example if I have a module rgb with a tag Red and another module rgba with Red there isn't a great way to work with both. To me it makes more sense to use them as imported types, rather than just by name. Is there any plan for this?

Also having type alias support for unions would be great! Something like Color = [Red, Blue] (not sure if that exists and I'm just missing that). I think combining these two features would make for my favorite effect system I've seen

view this post on Zulip Sven van Caem (Aug 29 2023 at 14:24):

Hi :)

To answer your first question, I'd like to ask what your definition of "effect" is here? The terms "effect" and "effect system" in Roc refer to side effects, like printing the screen, accomplished using the Task type.

As for type aliases, those do exist! The syntax for those would be Color : [Red, Blue].

view this post on Zulip Brendan Hansknecht (Aug 29 2023 at 15:14):

You can make rgb distinct from rgba by using an opaque type.

RGB := [Red, Green, Blue]
RGBA := [Red, Green, Blue, Alpha]

That said, I probably wouldn't advise it. I would probably advise just using a type alias and typing functions. You can't pass an RGBA to a function with the type RGB -> U8.

view this post on Zulip Brendan Hansknecht (Aug 29 2023 at 15:18):

To me it makes more sense to use them as imported types, rather than just by name. Is there any plan for this?

Just to clarify. If you use opaque types, you would be required to write rgba.red. That would be an exported value that references the opaque type. Internally it would be defined as @RGBA Red

view this post on Zulip Brendan Hansknecht (Aug 29 2023 at 15:21):

Probably also useful to read more on open and closed tag unions and then add clarifying questions here.

view this post on Zulip Agus Zubiaga (Aug 30 2023 at 01:07):

I also thought they should be namespaced at first but then I realized you can use the same tag name and hold different types and I understood why this is not necessary

view this post on Zulip Agus Zubiaga (Aug 30 2023 at 01:12):

Also I think it’s kinda cool that you can use the same name for two unions within the same module. In Elm, some times I end up prefixing variants with the types name just because I can’t do this.

view this post on Zulip Matt Hunzinger (Aug 30 2023 at 02:34):

Oh wow that's perfect! Exactly what I was looking for thanks everyone

view this post on Zulip Matt Hunzinger (Aug 30 2023 at 02:36):

@Agus Zubiaga that's a really interesting point. I'm used to rust having very strict namespacing but that's often had me making multiple enums with the same variants, just with some added or removed. That might actually be super clever having the variants shared by name like that

view this post on Zulip Matt Hunzinger (Aug 30 2023 at 02:38):

@Sven van Caem as far as effects something like tasks and how you can combine them is what I was thinking of. It definitely looks like that be achieved with making your own effects or those type aliases so that's great


Last updated: Jun 16 2026 at 16:19 UTC