Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rybla/liquid-monadic-selectionsort
https://github.com/rybla/liquid-monadic-selectionsort
liquid-haskell
Last synced: 1 day ago
JSON representation
- Host: GitHub
- URL: https://github.com/rybla/liquid-monadic-selectionsort
- Owner: rybla
- License: bsd-3-clause
- Created: 2021-10-27T03:29:58.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2022-02-08T18:41:40.000Z (almost 3 years ago)
- Last Synced: 2024-11-07T11:13:44.844Z (about 2 months ago)
- Topics: liquid-haskell
- Language: Haskell
- Homepage:
- Size: 132 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: ChangeLog.md
- License: LICENSE
Awesome Lists containing this project
README
# liquid-monadic-selectionsort
## Pure Selection Sort
### Sorting
```haskell
{-@
sort :: List -> List
@-}
sort :: List -> List
sort Nil = Nil
sort (Cons x Nil) = Cons x Nil
sort (Cons x xs) =
let Cons x' xs' = select (Cons x xs)
in Cons x' (sort xs'){-@
select :: {xs:List | 0 < lng xs} -> {xs':List | lng xs == lng xs'}
@-}
select :: List -> List
select (Cons x Nil) = Cons x Nil
select (Cons x1 (Cons x2 xs)) =
if x1 <= x2
then
let (Cons x' xs') = select (Cons x1 xs)
in Cons x' (Cons x2 xs')
else
let (Cons x' xs') = select (Cons x2 xs)
in Cons x' (Cons x1 xs')
```### Correctness Specifications
```haskell
{-@
sorted_sort :: xs:List -> Sorted {sort xs}
@-}
sorted_sort :: List -> Sorted{-@
permuted_sort :: xs:List -> Permuted {xs} {sort xs}
@-}
permuted_sort :: List -> Permuted
```### Proofs of Correctness
See module `SelectionSort/Pure.hs`.
### Predicates
```haskell
-- the list XS is sorted
{-@
type Sorted XS = {i:Int | inBounds xs i} -> {j:Int | inBounds xs j && i <= j} -> {index XS i <= index XS j}
@-}
type Sorted = Int -> Int -> Proof-- the list XS is a permutation of the list YS
{-@
type Permuted XS YS = z:Int -> {permutedAt XS YS z}
@-}
type Permuted = Int -> ProofpermutedAt :: List -> List -> Int -> Bool
permutedAt xs ys z = count xs z == count ys z-- the int X is less than or equal to each element of XS
{-@
type LeAll X XS = y:Int -> {contains XS y => X <= y}
@-}
type LeAll = Int -> Proof
```### Performance
```
stack build 69.37s user 8.18s system 93% cpu 1:22.88 total
```## Stateful Selection Sort
TODO