https://github.com/roc-lang/basic-cli/blob/main/platform/InternalHttp.roc#L14
Header : [Header Str Str]
is this a recursive type definition?
Why is header defined this way? Why not just headers: List {name: Str, value: Str}
? @Richard Feldman
Not sure if I have the correct syntax, but I meant a list of key value pairs
Header : [Header Str Str]
This is not recursive
What's the meaning?
This is a tag union called Header
with a single variant called Header
.
What will a tag union with >=2 variants look like?
Header : [
WithVal Str Str,
NoVal Str,
]
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
Header: [
WithVal Str Str,
NoVal Str,
]
``` with or without the `:`?
oh sorry, with the :
Do you mean that Header: [Header Str Str]
is effective the same as Header: (Str, Str)
?
They are different types in Roc, but will they be compiled to the same code?
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:
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)
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