compiler
compiler copied to clipboard
Tuple size limitation is too small
Quick Summary: ???
Elm 0.19.1 limits the tuple size to 3, which is too small.
I understand that the limitation is to help to increase the readability of the code. But there are cases that tuples cannot be replaced with records, namely if I want to deduplicate a list of records, I have to convert it to a list of tuples, then dedup it with a round trip to and from Set. Right now I have to use something like (a, b, (c, d)) to by pass the tuple size limitation.
Thanks for reporting this! To set expectations:
- Issues are reviewed in batches, so it can take some time to get a response.
- Ask questions a community forum. You will get an answer quicker that way!
- If you experience something similar, open a new issue. We like duplicates.
Finally, please be patient with the core team. They are trying their best with limited resources.
If you don't want to use nested tuples, you could also use a list of list, with something like [a, b, c, d], as lists are also comparable.
The root of your issue is also more that records are not comparable than a too small maximum size of tuples.
As an aside, you can remove duplicates from a list with a single traversal (building a test Set all along), without changing the initial ordering, see List.Extra.uniqueBy.
I thought list is homogeneous.
The root cause of this particular issue is that records are not comparable, but I think the upper limit is too small, regardless of this particular problem.
Yes, a list would work only if all values have the same type. This won't happen often for records fields indeed.
Another way to avoid the awkward syntax of nested tuples and to avoid having to think how to nest them is to use a pipeline approach, for example:
import List.Extra
type alias Record =
{ a : Int
, b : String
, c : Float
}
unique : List Record -> List Record
unique =
List.Extra.uniqueBy
(\rec ->
rec.a
|> Tuple.pair rec.b
|> Tuple.pair rec.c
)
A benefit is that the syntax scales well whatever the number of fields. This might have a slight performance impact though, to check with some benchmarks.