Copyright | (c) 2020-2021 Tim Emiola |
---|---|
License | BSD3 |
Maintainer | Tim Emiola <adetokunbo@users.noreply.github.com> |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Defines type-level combinators for performing a merge sort of type-level lists.
SortSymbols
sorts type-level lists of Symbols
.
The other exported combinators make it easy to implement type-level merge sort for similar type-level lists.
This is an internal module that provides type-level functions used in various constraints in System.TmpProc.Docker.
Merge sort for Symbols
.
type family SortSymbols (xs :: [Symbol]) :: [Symbol] where ... Source #
Sort a list of type-level symbols
using merge sort.
Examples
>>>
:kind! SortSymbols '["xyz", "def", "abc"]
SortSymbols '["xyz", "def", "abc"] :: [Symbol] = '["abc", "def", "xyz"]
SortSymbols '[] = '[] | |
SortSymbols '[x] = '[x] | |
SortSymbols '[x, y] = MergeSymbols '[x] '[y] | |
SortSymbols xs = SortSymbolsStep xs (HalfOf (LengthOf xs)) |
Sort combinators
type family Take (xs :: [k]) (n :: Nat) :: [k] where ... Source #
Takes 1 element at a time from a list until the desired length is reached.
Examples
>>>
:kind! Take '[1, 2, 3, 4] 2
Take '[1, 2, 3, 4] 2 :: [Nat] = '[1, 2]
type family Drop (xs :: [k]) (n :: Nat) :: [k] where ... Source #
Drops 1 element at a time until the the dropped target is reached.
Examples
>>>
:kind! Drop '[1, 2, 3, 4] 2
Drop '[1, 2, 3, 4] 2 :: [Nat] = '[3, 4]
>>>
:kind! Drop '[1] 2
Drop '[1] 2 :: [Nat] = '[]
type family LengthOf (xs :: [k]) :: Nat where ... Source #
Counts a list, 1 element at a time.
Examples
>>>
:kind! LengthOf '[1, 2, 3, 4]
LengthOf '[1, 2, 3, 4] :: Nat = 4