Tuple spread syntax #2376
Replies: 1 comment 1 reply
-
The two features here are being able to append to tuples, and being able to call functions with tuples as arguments, is that right? It seems to be quite clear what the code does and how codegen would work, that's nice. One thing to consider is that appending to a tuple means copying the entire tuple, it's not efficient like prepending to a list. With small tuples this is fine, but I worry that some folks may try and use tuples like arrays with this feature, and it's likely not a pattern we want to encourage. It's unclear to me how this works at the type level. For example, what is This reminds me a lot of row types in Elm, PureScript, etc. It's very easy to get very bad error messages here coming from type parameters, so we'd need to think carefully about that. |
Beta Was this translation helpful? Give feedback.
-
Thinking about the current, undesirable fnN pattern (e.g. for decoders), I started from @schurhammer's recent idea, then came to the conclusion that it might be pretty clean and simple if we could spread tuples into at least other tuples and fn args, and spread tuple types into other tuple types and fn type parameters. Somewhat naively, it seems the type system would still be able to help as much as it does now. This would also open up other possibilities like building up fn args recursively for other use cases; there is certainly more to think about in this regard.
Here's a gist for an (unsafe, currently) proof of concept for the above code, targeting Erlang.
Other thoughts
Tuples are a bit like anonymous records, but otherwise a unique data type, so perhaps having a spread syntax for them in the type system and otherwise won't be too confusing, in case anyone wonders why they're "special."
Perhaps the spread syntax could be extended for records as well.
Beta Was this translation helpful? Give feedback.
All reactions