HList-0.5.0.0: Heterogeneous lists

Safe HaskellNone
LanguageHaskell2010

Data.HList.HSort

Contents

Description

Benchmarks for these functions can be found at http://code.haskell.org/~aavogt/HList-nodup/Run.html.

See Data-HList-CommonMain.html#v:hSort for the public interface.

Synopsis

Documentation

data HLeFn Source #

the "standard" <= for types. Reuses HEqBy

Note that ghc-7.6 is missing instances for Symbol and Nat, so that sorting only works HNat (as used by Data.HList.Label3).

Instances

HEqByFn * HLeFn Source # 
(~) Bool ((<=?) x y) b => HEqBy * Nat HLeFn x y b Source #

only in ghc >= 7.7

(HEq Ordering (CmpSymbol x y) GT nb, (~) Bool (HNot nb) b) => HEqBy * Symbol HLeFn x y b Source #

only in ghc >= 7.7

>>> let b1 = Proxy :: HEqBy HLeFn "x" "y" b => Proxy b
>>> :t b1
b1 :: Proxy 'True
>>> let b2 = Proxy :: HEqBy HLeFn "x" "x" b => Proxy b
>>> :t b2
b2 :: Proxy 'True
>>> let b3 = Proxy :: HEqBy HLeFn "y" "x" b => Proxy b
>>> :t b3
b3 :: Proxy 'False
(~) Bool (HLe x y) b => HEqBy * HNat HLeFn x y b Source # 
HEqBy * k HLeFn x y b => HEqBy * * HLeFn (Proxy k x) (Proxy k y) b Source # 
HEqBy * k HLeFn x y b => HEqBy * * HLeFn (Label k x) (Label k y) b Source # 
HEqBy * k HLeFn x y b => HEqBy * * HLeFn (Tagged k x v) (Tagged k y w) b Source # 
(HEqBy * HNat HLeFn n m b, (~) * ns ns') => HEqBy * * HLeFn (Lbl n ns desc) (Lbl m ns' desc') b Source #

Data.HList.Label3 labels can only be compared if they belong to the same namespace.

data HDown a Source #

analogous to Down

Instances

HEqBy k2 k1 f y x b => HEqBy * k1 (HDown k2 f) x y b Source # 
HEqByFn k a => HEqByFn * (HDown k a) Source # 

data HNeq le Source #

The HEqBy instances for HNeq HLeFn gives <

Instances

(HEqBy k2 k1 le y x b1, (~) Bool (HNot b1) b2) => HEqBy * k1 (HNeq k2 le) x y b2 Source # 
HEqByFn k a => HEqByFn * (HNeq k a) Source # 

class HEqByFn le => HIsAscList le (xs :: [*]) (b :: Bool) | le xs -> b Source #

HIsAscList le xs b is analogous to

b = all (\(x,y) -> x `le` y) (xs `zip` tail xs)

Instances

HEqByFn k le => HIsAscList k le ([] *) True Source # 
(HEqBy k * le x y b1, HIsAscList k le ((:) * y ys) b2, (~) Bool (HAnd b1 b2) b3) => HIsAscList k le ((:) * x ((:) * y ys)) b3 Source # 
HEqByFn k le => HIsAscList k le ((:) * x ([] *)) True Source # 

class (SameLength a b, HEqByFn le) => HSortBy le (a :: [*]) (b :: [*]) | le a -> b where Source #

quick sort with a special case for sorted lists

Minimal complete definition

hSortBy

Methods

hSortBy :: Proxy le -> HList a -> HList b Source #

Instances

(SameLength * * a b, HIsAscList k le a ok, HSortBy1 Bool k ok le a b, HEqByFn k le) => HSortBy k le a b Source # 

Methods

hSortBy :: Proxy le a -> HList b -> HList b Source #

type HSort x y = HSortBy HLeFn x y Source #

hSort :: HSort x y => HList x -> HList y Source #

class HSortBy1 ok le (a :: [*]) (b :: [*]) | ok le a -> b where Source #

Minimal complete definition

hSortBy1

Methods

hSortBy1 :: Proxy ok -> Proxy le -> HList a -> HList b Source #

Instances

HSortBy1 Bool k True le a a Source # 

Methods

hSortBy1 :: Proxy True a -> Proxy le a -> HList a -> HList b Source #

HQSortBy k le a b => HSortBy1 Bool k False le a b Source # 

Methods

hSortBy1 :: Proxy False a -> Proxy le b -> HList a -> HList b Source #

Merge Sort

class HEqByFn le => HMSortBy le (a :: [*]) (b :: [*]) | le a -> b where Source #

HMSortBy is roughly a transcription of this merge sort

msort [] = []
msort [x] = [x]
msort [x,y] = hSort2 x y
msort xs = case splitAt (length xs `div` 2) xs of
             (a,b) -> msort a `merge` msort b
hSort2 x y
    | x <= y    = [x,y]
    | otherwise = [y,x]
merge (x : xs) (y : ys)
  | x > y     = y : merge (x : xs) ys
  | otherwise = x : merge xs (y : ys)

Minimal complete definition

hMSortBy

Methods

hMSortBy :: Proxy le -> HList a -> HList b Source #

Instances

HEqByFn k le => HMSortBy k le ([] *) ([] *) Source # 

Methods

hMSortBy :: Proxy le [*] -> HList [*] -> HList b Source #

(HSort2 Bool b x y ab, HEqBy k * le x y b) => HMSortBy k le ((:) * x ((:) * y ([] *))) ab Source # 

Methods

hMSortBy :: Proxy le ((* ': x) ((* ': y) [*])) -> HList ab -> HList b Source #

(HMerge k le xs' ys' sorted, HMSortBy k le ys ys', HMSortBy k le xs xs', HLengthEq ((:) * a ((:) * b ((:) * c cs))) n2, (~) HNat (HDiv2 n2) n, HSplitAt n ((:) * a ((:) * b ((:) * c cs))) xs ys) => HMSortBy k le ((:) * a ((:) * b ((:) * c cs))) sorted Source # 

Methods

hMSortBy :: Proxy le ((* ': a) ((* ': b) ((* ': c) cs))) -> HList sorted -> HList b Source #

HEqByFn k le => HMSortBy k le ((:) * x ([] *)) ((:) * x ([] *)) Source # 

Methods

hMSortBy :: Proxy le ((* ': x) [*]) -> HList ((* ': x) [*]) -> HList b Source #

class HSort2 b x y ab | b x y -> ab where Source #

Minimal complete definition

hSort2

Methods

hSort2 :: Proxy b -> x -> y -> HList ab Source #

Instances

HSort2 Bool False x y ((:) * y ((:) * x ([] *))) Source # 

Methods

hSort2 :: Proxy False x -> y -> (* ': y) ((* ': x) [*]) -> HList ab Source #

HSort2 Bool True x y ((:) * x ((:) * y ([] *))) Source # 

Methods

hSort2 :: Proxy True x -> y -> (* ': x) ((* ': y) [*]) -> HList ab Source #

class HMerge le x y xy | le x y -> xy where Source #

Minimal complete definition

hMerge

Methods

hMerge :: Proxy le -> HList x -> HList y -> HList xy Source #

Instances

HMerge k le ([] *) ([] *) ([] *) Source # 

Methods

hMerge :: Proxy le [*] -> HList [*] -> HList [*] -> HList xy Source #

HMerge k le ([] *) ((:) * x xs) ((:) * x xs) Source # 

Methods

hMerge :: Proxy le [*] -> HList ((* ': x) xs) -> HList ((* ': x) xs) -> HList xy Source #

HMerge k le ((:) * x xs) ([] *) ((:) * x xs) Source # 

Methods

hMerge :: Proxy le ((* ': x) xs) -> HList [*] -> HList ((* ': x) xs) -> HList xy Source #

(HEqBy k * le x y b, HMerge1 b ((:) * x xs) ((:) * y ys) ((:) * l ls) hhs, HMerge k le ls hhs srt) => HMerge k le ((:) * x xs) ((:) * y ys) ((:) * l srt) Source # 

Methods

hMerge :: Proxy le ((* ': x) xs) -> HList ((* ': y) ys) -> HList ((* ': l) srt) -> HList xy Source #

type HMerge1 b x y min max = (HCond b (HList x) (HList y) (HList min), HCond b (HList y) (HList x) (HList max)) Source #

hMerge1 :: (HCond t x y b, HCond t y x a) => Proxy Bool t -> y -> x -> (a, b) Source #

Quick sort

class HQSortBy le (a :: [*]) (b :: [*]) | le a -> b where Source #

HQSortBy is this algorithm

qsort (x : xs @ (_ : _)) = case partition (<= x) xs of
                 (le, gt) -> qsort le ++ x : qsort gt
qsort xs = xs

on random inputs that are not pathological (ie. not already sorted or reverse sorted) this turns out to be faster than HMSortBy, so it is used by default.

Minimal complete definition

hQSortBy

Methods

hQSortBy :: Proxy le -> HList a -> HList b Source #

Instances

HQSortBy k le ([] *) ([] *) Source # 

Methods

hQSortBy :: Proxy le [*] -> HList [*] -> HList b Source #

(HPartitionEq k * le a ((:) * b bs) bGeq bLt, HQSortBy k le bLt sortedLt, HQSortBy k le bGeq sortedGeq, (~) [*] (HAppendListR * sortedLt ((:) * a sortedGeq)) sorted, HAppendList sortedLt ((:) * a sortedGeq)) => HQSortBy k le ((:) * a ((:) * b bs)) sorted Source # 

Methods

hQSortBy :: Proxy le ((* ': a) ((* ': b) bs)) -> HList sorted -> HList b Source #

HQSortBy k le ((:) * x ([] *)) ((:) * x ([] *)) Source # 

Methods

hQSortBy :: Proxy le ((* ': x) [*]) -> HList ((* ': x) [*]) -> HList b Source #

More efficient HRLabelSet / HLabelSet

class HEqByFn lt => HSetBy lt (ps :: [*]) Source #

Provided the labels involved have an appropriate instance of HEqByFn, it would be possible to use the following definitions:

type HRLabelSet = HSet
type HLabelSet  = HSet

Instances

(HEqByFn k lt, HSortBy k lt ps ps', HAscList k lt ps') => HSetBy k lt ps Source # 

class HSetBy (HNeq HLeFn) ps => HSet (ps :: [*]) Source #

Instances

HSetBy * (HNeq * HLeFn) ps => HSet ps Source # 

class HIsSet (ps :: [*]) (b :: Bool) | ps -> b Source #

>>> let xx = Proxy :: HIsSet [Label "x", Label "x"] b => Proxy b
>>> :t xx
xx :: Proxy 'False
>>> let xy = Proxy :: HIsSet [Label "x", Label "y"] b => Proxy b
>>> :t xy
xy :: Proxy 'True

Instances

HIsSetBy * (HNeq * HLeFn) ps b => HIsSet ps b Source # 

class HEqByFn lt => HIsSetBy lt (ps :: [*]) (b :: Bool) | lt ps -> b Source #

Instances

(HEqByFn k lt, HSortBy k lt ps ps', HIsAscList k lt ps' b) => HIsSetBy k lt ps b Source # 

class HEqByFn le => HAscList le (ps :: [*]) Source #

HAscList le xs confirms that xs is in ascending order, and reports which element is duplicated otherwise.

Instances

(HEqByFn k le, HAscList0 k le ps ps) => HAscList k le ps Source # 

class HEqByFn le => HAscList0 le (ps :: [*]) (ps0 :: [*]) Source #

Instances

HEqByFn k le => HAscList0 k le ([] *) ps0 Source # 
HEqByFn k le => HAscList0 k le ((:) * x ([] *)) ps0 Source # 
(HAscList1 k le b ((:) * y ys) ps0, HEqBy k * le x y b) => HAscList0 k le ((:) * x ((:) * y ys)) ps0 Source # 

class HEqByFn le => HAscList1 le (b :: Bool) (ps :: [*]) (ps0 :: [*]) Source #

Instances

HAscList0 k le ys ys0 => HAscList1 k le True ys ys0 Source # 
(Fail (Symbol, *, Symbol, k, Symbol, [*]) ((,,,,,) Symbol * Symbol k Symbol [*] "Duplicated element" y "using le" le "in" ys0), HEqByFn k le) => HAscList1 k le False ((:) * y ys) ys0 Source # 
>>> import Data.HList.TypeEqO