> if I’m remembering `DateTime.compare/2` correctly
Close! The `Module.compare/2` functions return one of `:lt`, `:eq`, or `:gt` ("less than", "equal to", "greater than"), similar to what Haskell does. You may have been thinking of something like OCaml where `compare` returns `-1`, `0`, or `1` resp.
> So Why don't we implicitly sort it so that it can be compared by inequality sign(> or <)?
To clarify, functions like `<`
define the sort order.
Any time you sort a list, you're using a function that compares two elements. Even if you call `Enum.sort/1`, you're implicitly using `<=/2` as the comparison function. If you want some other sort order, e.g. for semantic ordering of `DateTime`s, then you must supply your own comparison function.
The reason that you can use `<` on structs with `CompareChain` is that it uses macros to re-write an expression like
`~D[2023-03-03] < ~D[2023-03-04]`
as
`Date.compare(~D[2023-03-03], ~D[2023-03-04]) == :lt`.
But that doesn't change the behavior of `<` itself. We're basically stuck with what `<` and the like do. Though as José points out, that's actually a good thing.
(Side note, you actually have to call `compare?(~D[2023-03-03] < ~D[2023-03-04], Date)` with `CompareChain` to invoke the re-write. I just wanted the example to be more readable.)