Last active
August 29, 2015 14:23
-
-
Save edwinb/4fca14d54fb29316330b to your computer and use it in GitHub Desktop.
Type level quicksort
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
qsort : Ord a => List a -> List a | |
qsort [] = [] | |
qsort (x :: xs) = let (l, r) = partition (< x) xs in | |
assert_total (qsort l ++ x :: qsort r) -- assert totality otherwise it won't reduce in the type | |
data Singleton : a -> Type where | |
MkSingleton : Singleton x | |
t_qsort : Ord a => (xs : List a) -> Singleton (qsort xs) | |
t_qsort xs = MkSingleton | |
{- | |
*tlsort> t_qsort [1,6,9,2,4,7,3,5,8] | |
MkSingleton : Singleton [1, 2, 3, 4, 5, 6, 7, 8, 9] | |
-} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment