Created
July 2, 2015 09:07
-
-
Save qnikst/6a4e4693e817a48ac650 to your computer and use it in GitHub Desktop.
typelevel sort
This file contains 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
type Sort a = SortI a '[] | |
type family SortI a b where | |
SortI '[] b = b | |
SortI (a:?n ': as) '[] = SortI as '[ a :? n] | |
SortI (a:?n ': as) bs = SortI as (Insert (a:?n) bs) | |
type family Insert a b where | |
Insert (a :? n) '[] = '[ a :? n ] | |
Insert (a :? n) ( b :? m ': bs) = UnOrdering (CmpSymbol n m) | |
((a :? n) ': (b :? m) ': bs) | |
((a :? n) ': (b :? m) ': bs) | |
((b :? m) ': Insert (a :? n) bs) | |
type family UnOrdering x a b c where | |
UnOrdering 'LT a b c = a | |
UnOrdering 'EQ a b c = b | |
UnOrdering 'GT a b c = c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment