I'm curious. Is @MyOpaqueType 42
a no-op? What about List.map @MyOpaqueType items
?
Yes, it is the same as if the opaque type was unwrapped to the underlying type.
yeah so all of these have no runtime overhead:
they all get compiled down to the unwrapped version of the thing
and the unwrapping nests, so if you have an opaque wrapper around a record with one field and that one field is a single tag union with a payload of a string, all of that will be just a string at runtime
That’s awesome
also: records, tag union payloads, and tuples all have the exact same runtime representation
so there's no perf advantage to choosing a record, a single-tag union, or a tuple, as long as they all have the same number of fields
Will List.map
still walk through the list in my example above? Or can it somehow tell the function I passed is basically identity at runtime?
Wait, I thought Roc didn’t really have tuples. I’ve been using tags for that. Did I miss something?
they're WIP
like they parse but don't make it all the way through the pipeline yet :big_smile:
Nice! Have somewhere that I can check them out?
I think @Joshua Warner may have a branch with more somewhere?
Agus Zubiaga said:
Will
List.map
still walk through the list in my example above? Or can it somehow tell the function I passed is basically identity at runtime?
it will still walk through the list at the moment...I'd definitely like to optimize that away in the future if possible, but we don't have the optimization infrastructure in place to detect a pattern like that right now
That makes sense!
Great, thanks for the explanation
Love all this zero-overhead stuff
yeah part of the design goal with those is to remove the tension between choosing the nicest representation and choosing the fastest representation
ideally the contenders for nicest are all equally fast, so you only have that one axis to think about :big_smile:
Tuples should work; please file bugs if they don't!
Are there docs on tuples somewhere? I would love to try them out
Or even just a quick example of the syntax
f : I64 -> (I64, I64)
f = \x -> (x, x + 1)
f 42
Joshua Warner said:
Tuples should work; please file bugs if they don't!
found one! :big_smile:
https://github.com/roc-lang/roc/issues/5148
Last updated: Jul 06 2025 at 12:14 UTC