Allow casing over multiple expressions #222
Labels
accepted
The issue has been reviewed and accepted for implementation
language proposal
proposal of a major feature to the language
Casing over multiple expressions is something that comes up in several cases. Currently, you can do this by wrapping things up in a record and casing over that.
However, this isn't ideal as it requires allocating a data structure in order to perform the comparison, which is bad for hot loops. Also, for simple cases, it adds a bit of boilerplate (the names of the record fields) which, for a local single-used expression, doesn't add a ton of value.
To solve the efficiency problem, without loosing too much readability, one could allow for multiple expressions in a case of expression:
Alternatives
Previously Gren had tuples, which was quite often used for cases like these. However, tuples have the same performance overhead as records (they're compiled to the same thing) and tuples as a datastructre makes code more brittle as everything depends on the order of arguments. Positional semantics aren't that big of a deal in a single expression, but they're a problem when in a data structure.
The text was updated successfully, but these errors were encountered: