Stream: compiler development

Topic: Sort ability implementation


view this post on Zulip Jasper Woudenberg (Apr 01 2024 at 13:21):

Hi there! I've picked up this issue related to implementing a new Sort ability for comparisons between types.

One conclusion from earlier discussion is that Sort should not be implemented by Str, because it would be ambiguous, and another in the issue is that it's fine to initially not have it for F32 and F64 either (similar to Eq). That all makes sense!

Got a couple of other questions that I could use some guidance on:

view this post on Zulip Richard Feldman (Apr 01 2024 at 13:51):

Jasper Woudenberg said:

Do we want auto-derived Sort for arbitrary types, similar to Eq?

yes!

Should <, <=, >, >= work using Sort?

I don't think so - I think they should continue to use Num. It's always seemed like a footgun to me that in many languages I can write "chair" < "hamburger" and have the type checker accept it. I think it's best if that's a mismatch! :big_smile:

Which module would we like Sort to live in? A new one? List?

let's put it in List for now and see how that feels :thumbs_up:

view this post on Zulip Brendan Hansknecht (Apr 01 2024 at 14:39):

Isn't "chair" < "hamburger" only a problem cause string sorting is ambiguous?

view this post on Zulip Richard Feldman (Apr 01 2024 at 14:46):

it's not just a problem of "what's the answer" it's also a problem of "this is not code that should be written this way on purpose" :big_smile:

view this post on Zulip Richard Feldman (Apr 01 2024 at 14:47):

but it can of course absolutely be written this way by mistake

view this post on Zulip Richard Feldman (Apr 01 2024 at 14:47):

so the combination of "shouldn't be written this way on purpose" and "the compiler can tell you when you've written it this way, in case you've made a mistake" leads me to the preference of wanting it to be a compiler error


Last updated: Jul 06 2025 at 12:14 UTC