Stream: beginners

Topic: tag-unions


view this post on Zulip Richard Feldman (Oct 27 2020 at 03:16):

I just rewrote the whole roc-for-elm-programmer.md section on tags based on some design ideas we've been discussing - love to hear any feedback anyone has about it!

https://github.com/rtfeldman/roc/blob/7ce0e4418225602d5b4123635a757dc46089868c/roc-for-elm-programmers.md#custom-types

view this post on Zulip Zeljko Nesic (Oct 27 2020 at 08:13):

Ooh, < Type > is a new notation?

view this post on Zulip Zeljko Nesic (Oct 27 2020 at 08:16):

Ok, coffee made me too reactive, just saw other sentence. :)
By the way, inside a tag union annotation, the < and > angle brackets around each tag are syntactically optional because they don't add any information.

Is there a reason to keep < > notation if above holds true?

view this post on Zulip Zeljko Nesic (Oct 27 2020 at 08:18):

As always maybe there is a pedagogical use of it to not mix lists and tag unions

> y = Foo [ 1.1 ] "hi"
Foo [ 1.1 ] "hi" : <Foo (List Float) Str>

> z = Foo "hi" True
Foo "hi" True : <Foo Str <True>>

view this post on Zulip Richard Feldman (Oct 27 2020 at 23:05):

Is there a reason to keep < > notation if above holds true?

yes! There are two reasons:

  1. Hopefully making it easier to learn how tags and tag unions work. (Maybe this doesn't help though - I'm not sure!) An alternative design would be to have the type of a Foo value on its own be [ Foo ]* like it is today (whereas in this draft it'd be <Foo> instead).
  2. It's arguably nicer in some type signatures, for example:
List.first : List a -> Result a <ListWasEmpty>

instead of

List.first : List a -> Result a [ ListWasEmpty ]*

view this post on Zulip Richard Feldman (Oct 27 2020 at 23:06):

but I'm honestly not sure overall if this is an improvement, or if we should stick to [ ]* over < >

view this post on Zulip Brendan Hansknecht (Oct 27 2020 at 23:38):

My only issue with < > is that you are forced to deal with both [ Bar, Baz ]* and <Baz> vs [ Bar, Baz ]* and [Baz]*

view this post on Zulip Brendan Hansknecht (Oct 27 2020 at 23:40):

So like you have to learn 2 pieces of syntax instead of just one.

view this post on Zulip Richard Feldman (Oct 27 2020 at 23:41):

fair point!

view this post on Zulip Richard Feldman (Oct 27 2020 at 23:47):

would it be weird if values of [ Foo ]* could be passed to things that wanted functions? e.g. if [ Foo ]* could be passed to a function that wanted [ Foo ]* or a -> [ Foo a ]* or a, b -> [ Foo a b ]* or a, b, c -> [ Foo a b c ]* etc?

view this post on Zulip Richard Feldman (Oct 27 2020 at 23:48):

(I thought it might be less weird with the <Foo> syntax, but maybe that's not helping?)

view this post on Zulip Brendan Hansknecht (Oct 28 2020 at 00:09):

Ah, i see. Hmmm. That's a really valid point for separate syntax.

view this post on Zulip Richard Feldman (Oct 28 2020 at 02:23):

:thinking: I wonder if it might be more straightforward if the rule were "<Foo> is syntax sugar for [ Foo ]*"

view this post on Zulip Chad Stearns (Oct 28 2020 at 19:58):

I kind of like [ Foo ]* over <Foo> too. Not because its more or less confusing, but because I like there being just one way to convey that (they would be co-existing alternatives? If <Foo> was a thing, then [ Foo ]* would still be valid right?

view this post on Zulip Chad Stearns (Oct 28 2020 at 20:01):

What would be the natural way of reading [ Foo ]*? "At least Foo"? What about <Foo>? If its the same thing, I guess it should read the same way in natural language, but it kind of feels different to me. Like its meant to convey that it is just Foo and nothing else.

view this post on Zulip Chad Stearns (Oct 28 2020 at 20:03):

Not sure! Just sharing my impressions. I guess the wild card ultimately means "and nothing else" in the same way that List * is necessarily empty, but can be joined with something non-empty, so [ Foo ]* is "a group containing Foo and also nothing else"

view this post on Zulip Zeljko Nesic (Oct 30 2020 at 13:54):

Maybe, if we kick out parenthesis from tag unions?

Song : Fun , Sad Int, Sexy (Result Str (Male, Female, Alien,|*)), |*

and we can even have functions xx: Foo |* -> Foo, Bar or extendFoo : Foo -> Foo, Bar, Faux |*

view this post on Zulip Zeljko Nesic (Oct 30 2020 at 13:55):

Where |* would serve as ]* as currently is it can easy only be just *


Last updated: Jul 06 2025 at 12:14 UTC