| 1 |
------------------------------------------------------------------------ |
| 2 |
-- The Agda standard library |
| 3 |
-- |
| 4 |
-- Functions and definitions for sorting lists |
| 5 |
------------------------------------------------------------------------ |
| 6 |
|
| 7 |
-- See `Data.List.Relation.Unary.Sorted` for the property of a list |
| 8 |
-- being sorted. |
| 9 |
|
| 10 |
{-# OPTIONS --cubical-compatible --safe #-} |
| 11 |
|
| 12 |
open import Relation.Binary.Bundles using (DecTotalOrder) |
| 13 |
|
| 14 |
module Data.List.Sort |
| 15 |
{a ℓ₁ ℓ₂} (O : DecTotalOrder a ℓ₁ ℓ₂) |
| 16 |
where |
| 17 |
|
| 18 |
open import Data.List.Base using (List) |
| 19 |
|
| 20 |
open DecTotalOrder O renaming (Carrier to A) |
| 21 |
|
| 22 |
------------------------------------------------------------------------ |
| 23 |
-- Re-export core definitions |
| 24 |
|
| 25 |
open import Data.List.Sort.Base totalOrder public |
| 26 |
using (SortingAlgorithm) |
| 27 |
|
| 28 |
------------------------------------------------------------------------ |
| 29 |
-- An instance of a sorting algorithm |
| 30 |
|
| 31 |
open import Data.List.Sort.MergeSort O using (mergeSort) |
| 32 |
|
| 33 |
abstract |
| 34 |
sortingAlgorithm : SortingAlgorithm |
| 35 |
sortingAlgorithm = mergeSort |
| 36 |
|
| 37 |
open SortingAlgorithm sortingAlgorithm public |
| 38 |
using |
| 39 |
( sort -- : List A → List A |
| 40 |
; sort-↭ -- : ∀ xs → sort xs ↭ xs |
| 41 |
; sort-↗ -- : ∀ xs → Sorted (sort xs) |
| 42 |
) |