Stream: beginners

Topic: basic cli


view this post on Zulip Albert (Jun 18 2024 at 17:00):

https://github.com/roc-lang/basic-cli/blob/main/platform/InternalHttp.roc#L14

view this post on Zulip Albert (Jun 18 2024 at 17:01):

Header : [Header Str Str] is this a recursive type definition?

view this post on Zulip Albert (Jun 18 2024 at 17:02):

Why is header defined this way? Why not just headers: List {name: Str, value: Str}? @Richard Feldman

view this post on Zulip Albert (Jun 18 2024 at 17:02):

Not sure if I have the correct syntax, but I meant a list of key value pairs

view this post on Zulip Brendan Hansknecht (Jun 18 2024 at 17:13):

Header : [Header Str Str]

This is not recursive

view this post on Zulip Albert (Jun 18 2024 at 17:13):

What's the meaning?

view this post on Zulip Brendan Hansknecht (Jun 18 2024 at 17:13):

This is a tag union called Header with a single variant called Header.

view this post on Zulip Albert (Jun 18 2024 at 17:14):

What will a tag union with >=2 variants look like?

view this post on Zulip Brendan Hansknecht (Jun 18 2024 at 17:15):

Header : [
  WithVal Str Str,
  NoVal Str,
]

view this post on Zulip Brendan Hansknecht (Jun 18 2024 at 17:15):

It probably should be defined as either (Str, Str) or {name: Str, value: Str}

I would guess that this code was written before we had tuples. Header : [Header Str Str] is kinda a weird tuple

view this post on Zulip Albert (Jun 18 2024 at 17:15):

Header: [
  WithVal Str Str,
  NoVal Str,
]
``` with or without the `:`?

view this post on Zulip Brendan Hansknecht (Jun 18 2024 at 17:16):

oh sorry, with the :

view this post on Zulip Albert (Jun 18 2024 at 17:18):

Do you mean that Header: [Header Str Str] is effective the same as Header: (Str, Str)?

view this post on Zulip Albert (Jun 18 2024 at 17:19):

They are different types in Roc, but will they be compiled to the same code?

view this post on Zulip Richard Feldman (Jun 18 2024 at 21:57):

yeah this is just old code I think; we used to have a different syntax for opaque types (basically; the feature worked a bit differently) that looked more like Header : [@Header Str Str] and my guess is that when we changed to the current design for opaque types ,we just dropped the @ as a quick fix there and it's just stayed that way ever since :laughing:

view this post on Zulip Richard Feldman (Jun 18 2024 at 21:58):

another possible explanation is that there was a long time where we had tag unions but not tuples, so you couldn't write Header : (Str, Str)

view this post on Zulip Richard Feldman (Jun 18 2024 at 21:58):

but yeah, there's no reason it needs to be [Header Str Str] and it seems reasonable to change it to something more sensible - either an opaque type or a tuple, most likely :thumbs_up:


Last updated: Jul 05 2025 at 12:14 UTC