Type classes are not and cannot ever be a replacement for modules. Anything that presses them into service in this manner is badly mistaken.

]]>For example, according to the philosophy of type classes, the integers can be ordered in precisely one way (the usual ordering), but obviously there are many orderings (say, by divisibility) of interest

I think you ignore that there is practical value in ascribing only one natural ordering to things.

I came across this in the context of Rust’s substructural type system for lifetimes, as well as linear logic and type theory being the “language of resources”.

In that context, it makes perfect sense for a typeclass to express natural ordering *as part of its type signature*, which is what it is doing by only expressing one ordering.

In the world of actual computation, traversal has cost, and locality of traversal (e.g. linked list vs slice, or local machine memory vs distributed system) is essential to both performance and reliability of computation.

An Int can be traversed multiple ways, but any given instance of a list of Ints will only have one natural/physical ordering.

In a distributed system, you might have a petabyte of partitioned nested data structures that have a total ordering (the ordering of the partitions + the ordering of the partitioned data structure), and applying a total ordering transformation that resulted in random hops across the natural ordering would result in hugely inefficient computation.

So, it is essential to have the ability to express what the natural ordering is, due to the performance characteristics of locality, or the lack thereof.

Given that, wrapping one typeclass inside another seems like a perfectly logical way to express that the ordering that you *want* is a morphism of the natural ordering, rather than something that has its own magical existence. That ordering (at runtime), only exists because a (costly) function is being applied to the natural ordering.

In other words, linear logic manages your resources, and order transformation represents your cost to access those resources.

]]>