I'm looking into the possibility of making an Elm to Roc converter. One thing I noticed though was that, unless I'm missing something, it's not possible to implement Elm's List.sortBy : (a -> comparable) -> List a -> List a
due to comparable
not thing a thing in Roc? Is there a way to work around this?
For now, there is List.sortWith
which takes a list and a comparison function of type a, a -> [LT, EQ, GT]
. But I remember there being some discussion of adding a Compare ability or similar
https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/ordering.2Fsorting.20ability
Here is the discussion
Thanks, I'll have a look at that.
And @Jasper Woudenberg's WIP PR https://github.com/roc-lang/roc/pull/6615
Looking at the details I suspect this won't be exactly what I need. For example, if something like (String, F64)
isn't automatically treated as comparable then I'm probably not going to get very far. My hope of just doing a syntax level conversion between Elm and Roc was probably too optimistic :sweat_smile:
I think in that case it would have Sortable derived
Wouldn't it just be opaque types that need to be manually implemented
I thought Str
wouldn't get the ability because of unicode messiness?
Yeah, good point
What about instead of converting to a Roc Str type, make an opaque ElmStr
and convert to that. Then give it behaviour that matches Elm.
That would work I think, if tuples and other non-opaque types all automatically derive it as well
The plan is definitely that tuples/records/lists will be comparable to one-another!
Last updated: Jul 06 2025 at 12:14 UTC