Created
July 2, 2014 18:47
-
-
Save ctford/487f1c63ac63e3e22523 to your computer and use it in GitHub Desktop.
A length-safe insertion sort.
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
insert : Ord a => a -> Vect n a -> Vect (1 + n) a | |
insert x [] = [x] | |
insert x (y::ys) with (x <= y) | |
| True = x::y::ys | |
| False = y::insert x ys | |
isort : Ord a => Vect n a -> Vect n a | |
isort [] = [] | |
isort (x::xs) = insert x (isort xs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This isn't tail-recursive, so careful on memory usage!