Siddharth Bhat
Siddharth Bhat

Reputation: 843

Coq list sorting practices & sortBy?

What is the equivalent of Haskell's sortBy in Coq?

In general, I find the Coq standard library around sorting confusing.

I would have hoped for some "axiomatisation" of a sorted list, and the the availability of different sorts, to which I can provide an ordering function.

However, this does not seem to be the case.

Is there some implementation of sortBy I can use, or do I need to create this manually?

Upvotes: 2

Views: 366

Answers (2)

Arthur Azevedo De Amorim
Arthur Azevedo De Amorim

Reputation: 23612

Besides the Coq standard library, the Mathetical Components library also has an implementation of merge sort. It is called sort, and it lives in the module mathcomp.path. Its signature is forall T : Type, (T -> T -> bool) -> list T -> list T, which is closer to the original sortBy.

Upvotes: 2

Rob Blanco
Rob Blanco

Reputation: 306

The MergeSort module in the Coq standard library does what you need. It works like sortBy in Haskell except that instead of passing an ordering function and obtaining the specialized sort, you pass a module that encapsulates the ordering function along with the proof that this function is total. See the example at the bottom of the module documentation.

Upvotes: 3

Related Questions