HList-0.5.2.0: Heterogeneous lists
Safe HaskellNone
LanguageHaskell2010

Data.HList.RecordU

Description

The public interface is exported from RecordU

Synopsis

Type definitions

RecordUS

newtype RecordUS (x :: [*]) Source #

RecordUS is stored as a HList of RecordU to allow the RecordUS to contain elements of different types, so long all of the types can be put into an unboxed array (UArray).

It is advantageous (at least space-wise) to sort the record to keep elements with the same types elements adjacent. See SortForRecordUS for more details.

Constructors

RecordUS Any

Any here is the HList u given RecordUSCxt x u

Instances

Instances details
(HFindLabel l r n, HLookupByHNatUS n u (Tagged l v), HasField l (Record r) v, RecordUSCxt r u) => HasField (l :: k) (RecordUS r) v Source #

works expected. See examples attached to bad.

Instance details

Defined in Data.HList.RecordU

Methods

hLookupByLabel :: Label l -> RecordUS r -> v Source #

(RecordUSCxt x u, Show (HList u)) => Show (RecordUS x) Source # 
Instance details

Defined in Data.HList.RecordU

Methods

showsPrec :: Int -> RecordUS x -> ShowS #

show :: RecordUS x -> String #

showList :: [RecordUS x] -> ShowS #

class RecordUSCxt (x :: [*]) (u :: [*]) | x -> u, u -> x where Source #

connect the unpacked x representation with the corresponding list of RecordU u representation.

Minimal complete definition

Nothing

Methods

recordUSToHList :: RecordUS x -> HList u Source #

O(1) should be possible to implement this without unsafeCoerce, but we want to hide the u parameter _and_ keep the RecordUSCxt as a class (instead of a type family) because of HEq. In some cases it is possible to have instances that do not actually respect the functional dependency, but this should be safe if the check is not disabled (by using -XDysfunctionalDependencies https://phabricator.haskell.org/D69, or ghc-7.6)

hListToRecordUS :: HList u -> RecordUS x Source #

O(1) should be possible to implement this without unsafeCoerce

Instances

Instances details
(HGroupBy EqTagValue x g, HMapUnboxF g u) => RecordUSCxt x u Source #

the only instance

Instance details

Defined in Data.HList.RecordU

data EqTagValue Source #

Instances

Instances details
HEqByFn EqTagValue Source # 
Instance details

Defined in Data.HList.RecordU

(txv ~ Tagged x v, tyw ~ Tagged y w, HEq v w b) => HEqBy EqTagValue (txv :: Type) (tyw :: Type) b Source # 
Instance details

Defined in Data.HList.RecordU

class HMapUnboxF (xs :: [*]) (us :: [*]) | xs -> us, us -> xs Source #

proof that hMap UnboxF :: r xs -> r us can determine xs from us and us from xs

Instances

Instances details
HMapUnboxF ('[] :: [Type]) ('[] :: [Type]) Source # 
Instance details

Defined in Data.HList.RecordU

HMapUnboxF xs us => HMapUnboxF (HList x ': xs) (RecordU x ': us) Source # 
Instance details

Defined in Data.HList.RecordU

RecordU

newtype RecordU l Source #

A type which behaves similarly to Record, except all elements must fit in the same UArray. A consequence of this is that RecordU has the following properties:

  • it is strict in the element types
  • it cannot do type-changing updates of RecordU, except if the function applies to all elements
  • it probably is slower to update the very first elements of the RecordU

The benefit is that lookups should be faster and records should take up less space. However benchmarks done with a slow HNat2Integral do not suggest that RecordU is faster than Record.

Constructors

RecordU (UArray Int (GetElemTy l)) 

Instances

Instances details
(ApplyAB f (GetElemTy x) (GetElemTy y), IArray UArray (GetElemTy y), IArray UArray (GetElemTy x)) => HMapAux RecordU f x y Source # 
Instance details

Defined in Data.HList.RecordU

Methods

hMapAux :: f -> RecordU x -> RecordU y Source #

(r ~ r', v ~ GetElemTy r, HFindLabel l r n, HNat2Integral n, IArray UArray v, HasField l (Record r') v) => HUpdateAtLabel RecordU (l :: k) v r r' Source # 
Instance details

Defined in Data.HList.RecordU

Methods

hUpdateAtLabel :: Label l -> v -> RecordU r -> RecordU r' Source #

(s ~ t, a ~ b, IArray UArray a, a ~ GetElemTy s, HLensCxt x RecordU s t a b) => Labelable (x :: k) RecordU s t a b Source #

make a Lens' (RecordU s) a

Instance details

Defined in Data.HList.RecordU

Associated Types

type LabelableTy RecordU :: LabeledOpticType Source #

Methods

hLens' :: Label x -> LabeledOptic x RecordU s t a b Source #

(IArray UArray v, v ~ GetElemTy ls, HFindLabel l ls n, HNat2Integral n) => HasField (l :: k) (RecordU ls) v Source # 
Instance details

Defined in Data.HList.RecordU

Methods

hLookupByLabel :: Label l -> RecordU ls -> v Source #

(RecordValues lv, HList2List (RecordValuesR lv) v, HFindMany (LabelsOf lv) (LabelsOf r) ixs, IArray UArray v, v ~ GetElemTy r, HNats2Integrals ixs) => HUpdateMany lv (RecordU r) Source # 
Instance details

Defined in Data.HList.RecordU

Methods

hUpdateMany :: Record lv -> RecordU r -> RecordU r Source #

Eq (UArray Int (GetElemTy l)) => Eq (RecordU l) Source # 
Instance details

Defined in Data.HList.RecordU

Methods

(==) :: RecordU l -> RecordU l -> Bool #

(/=) :: RecordU l -> RecordU l -> Bool #

Ord (UArray Int (GetElemTy l)) => Ord (RecordU l) Source # 
Instance details

Defined in Data.HList.RecordU

Methods

compare :: RecordU l -> RecordU l -> Ordering #

(<) :: RecordU l -> RecordU l -> Bool #

(<=) :: RecordU l -> RecordU l -> Bool #

(>) :: RecordU l -> RecordU l -> Bool #

(>=) :: RecordU l -> RecordU l -> Bool #

max :: RecordU l -> RecordU l -> RecordU l #

min :: RecordU l -> RecordU l -> RecordU l #

Read (UArray Int (GetElemTy l)) => Read (RecordU l) Source # 
Instance details

Defined in Data.HList.RecordU

Show (UArray Int (GetElemTy l)) => Show (RecordU l) Source # 
Instance details

Defined in Data.HList.RecordU

Methods

showsPrec :: Int -> RecordU l -> ShowS #

show :: RecordU l -> String #

showList :: [RecordU l] -> ShowS #

HMapUnboxF xs us => HMapUnboxF (HList x ': xs) (RecordU x ': us) Source # 
Instance details

Defined in Data.HList.RecordU

type LabelableTy RecordU Source # 
Instance details

Defined in Data.HList.RecordU

type family GetElemTy (x :: [*]) :: * Source #

Instances

Instances details
type GetElemTy (Tagged label v ': rest) Source # 
Instance details

Defined in Data.HList.RecordU

type GetElemTy (Tagged label v ': rest) = v

class SortForRecordUS x x' | x -> x' where Source #

Reorders a Record such that the RecordUS made from it takes up less space

Bad has alternating Double and Int fields

>>> bad
Record{x=1.0,i=2,y=3.0,j=4}

4 arrays containing one element each are needed when this Record is stored as a RecordUS

>>> recordToRecordUS bad
RecordUS H[RecordU (array (0,0) [(0,1.0)]),RecordU (array (0,0) [(0,2)]),RecordU (array (0,0) [(0,3.0)]),RecordU (array (0,0) [(0,4)])]

It is possible to sort the record

>>> sortForRecordUS bad
Record{x=1.0,y=3.0,i=2,j=4}

This allows the same content to be stored in two unboxed arrays

>>> recordToRecordUS (sortForRecordUS bad)
RecordUS H[RecordU (array (0,1) [(0,1.0),(1,3.0)]),RecordU (array (0,1) [(0,2),(1,4)])]

Instances

Instances details
SortForRecordUS ('[] :: [Type]) ('[] :: [Type]) Source # 
Instance details

Defined in Data.HList.RecordU

Methods

sortForRecordUS :: Record '[] -> Record '[] Source #

(HPartitionEq EqTagValue x (x ': xs) xi xo, SortForRecordUS xo xo', sorted ~ HAppendListR xi xo', HAppendList xi xo') => SortForRecordUS (x ': xs) sorted Source # 
Instance details

Defined in Data.HList.RecordU

Methods

sortForRecordUS :: Record (x ': xs) -> Record sorted Source #

Lookup

class HLookupByHNatUS (n :: HNat) (us :: [*]) (e :: *) | n us -> e where Source #

Methods

hLookupByHNatUS :: Proxy n -> HList us -> e Source #

Instances

Instances details
(r ~ HSubtract (HLength u) n, RecordU u ~ ru, HLookupByHNatUS1 r n u us e) => HLookupByHNatUS n (ru ': us) e Source # 
Instance details

Defined in Data.HList.RecordU

Methods

hLookupByHNatUS :: Proxy n -> HList (ru ': us) -> e Source #

class HLookupByHNatUS1 (r :: Either HNat HNat) (n :: HNat) (u :: [*]) (us :: [*]) (e :: *) | r n u us -> e where Source #

Methods

hLookupByHNatUS1 :: Proxy r -> Proxy n -> RecordU u -> HList us -> e Source #

Instances

Instances details
(HNat2Integral n, HLookupByHNatR n u ~ le, le ~ Tagged l e, IArray UArray e, e ~ GetElemTy u) => HLookupByHNatUS1 ('Left t :: Either HNat HNat) n u us le Source # 
Instance details

Defined in Data.HList.RecordU

Methods

hLookupByHNatUS1 :: Proxy ('Left t) -> Proxy n -> RecordU u -> HList us -> le Source #

HLookupByHNatUS t us e => HLookupByHNatUS1 ('Right t :: Either HNat HNat) n u us e Source # 
Instance details

Defined in Data.HList.RecordU

Methods

hLookupByHNatUS1 :: Proxy ('Right t) -> Proxy n -> RecordU u -> HList us -> e Source #

type family HSubtract (n1 :: HNat) (n2 :: HNat) :: Either HNat HNat Source #

HSubtract a b is Left (a-b), Right (b-a) or Right HZero

Instances

Instances details
type HSubtract 'HZero 'HZero Source # 
Instance details

Defined in Data.HList.RecordU

type HSubtract 'HZero ('HSucc y) Source # 
Instance details

Defined in Data.HList.RecordU

type HSubtract 'HZero ('HSucc y) = 'Right ('HSucc y) :: Either HNat HNat
type HSubtract ('HSucc y) 'HZero Source # 
Instance details

Defined in Data.HList.RecordU

type HSubtract ('HSucc y) 'HZero = 'Left ('HSucc y) :: Either HNat HNat
type HSubtract ('HSucc x) ('HSucc y) Source # 
Instance details

Defined in Data.HList.RecordU

type HSubtract ('HSucc x) ('HSucc y) = HSubtract x y

Conversion of RecordUS

with the actual representation

recordUS :: forall p f (x1 :: [Type]) (g1 :: [Type]) (x2 :: [Type]) (g2 :: [Type]) (u1 :: [Type]) (u2 :: [Type]). (Profunctor p, Functor f, HGroupBy EqTagValue x1 g1, HGroupBy EqTagValue x2 g2, HMapUnboxF g1 u1, HMapUnboxF g2 u2) => p (RecordUS x1) (f (RecordUS x2)) -> p (HList u1) (f (HList u2)) Source #

Iso (HList s) (HList t) (RecordUS a) (RecordUS b)

recordUS' :: forall (x :: [Type]) (g :: [Type]) f p (u :: [Type]). (HGroupBy EqTagValue x g, Functor f, Profunctor p, HMapUnboxF g u) => p (RecordUS x) (f (RecordUS x)) -> p (HList u) (f (HList u)) Source #

Iso (HList s) (RecordUS a)

s is a HList of RecordU while a :: [*] is list of Tagged label value

with Record

recordToRecordUS :: forall x g u. (HMapCxt HList UnboxF g u, HMapUnboxF g u, HGroupBy EqTagValue x g, RecordUSCxt x u) => Record x -> RecordUS x Source #

view unboxedS or ^. unboxedS are preferred

recordUSToRecord :: forall u g x. (HConcatFD g x, HMapCxt HList BoxF u g, HMapUnboxF g u, RecordUSCxt x u) => RecordUS x -> Record x Source #

^. from unboxedS is preferred

unboxedS :: forall (g1 :: [Type]) (u1 :: [Type]) (g2 :: [Type]) (u2 :: [Type]) (x1 :: [Type]) (x2 :: [Type]) p f. (HMapUnboxF g1 u1, HMapUnboxF g2 u2, HGroupBy EqTagValue x1 g1, HGroupBy EqTagValue x2 g2, Profunctor p, Functor f, HConcatFD g1 x1, SameLength' u2 g2, SameLength' g2 u2, SameLength' u1 g1, SameLength' g1 u1, HMapAux HList UnboxF g2 u2, HMapAux HList BoxF u1 g1) => p (RecordUS x2) (f (RecordUS x1)) -> p (Record x2) (f (Record x1)) Source #

Iso (Record x) (Record y) (RecordUS x) (RecordUS y)

unboxedS' :: forall (g :: [Type]) (u :: [Type]) (x :: [Type]) p f. (HMapUnboxF g u, HGroupBy EqTagValue x g, Profunctor p, Functor f, HConcatFD g x, SameLength' u g, SameLength' g u, HMapAux HList UnboxF g u, HMapAux HList BoxF u g) => p (RecordUS x) (f (RecordUS x)) -> p (Record x) (f (Record x)) Source #

Iso' (Record x) (RecordUS x)

class ElemTyEq (xs :: [*]) Source #

all elements of the list have the same type

Instances

Instances details
ElemTyEq ('[] :: [Type]) Source # 
Instance details

Defined in Data.HList.RecordU

t1v ~ Tagged t v => ElemTyEq (t1v ': rest) Source # 
Instance details

Defined in Data.HList.RecordU

(t1v ~ Tagged t1 v, t2v ~ Tagged t2 v, ElemTyEq (tv2 ': rest)) => ElemTyEq (tv1 ': (tv2 ': rest)) Source # 
Instance details

Defined in Data.HList.RecordU

class HUpdateMany lv rx where Source #

analogous flip //. Similar to .<++., except it is restricted to cases where the left argument holds a subset of elements.

Methods

hUpdateMany :: Record lv -> rx -> rx Source #

Instances

Instances details
(HLeftUnion lv x lvx, HRLabelSet x, HLabelSet (LabelsOf x), HRearrange (LabelsOf x) lvx x) => HUpdateMany lv (Record x) Source #

implementation in terms of .<++.

Instance details

Defined in Data.HList.RecordU

Methods

hUpdateMany :: Record lv -> Record x -> Record x Source #

(RecordValues lv, HList2List (RecordValuesR lv) v, HFindMany (LabelsOf lv) (LabelsOf r) ixs, IArray UArray v, v ~ GetElemTy r, HNats2Integrals ixs) => HUpdateMany lv (RecordU r) Source # 
Instance details

Defined in Data.HList.RecordU

Methods

hUpdateMany :: Record lv -> RecordU r -> RecordU r Source #

class HFindMany (ls :: [k]) (r :: [k]) (ns :: [HNat]) | ls r -> ns Source #

behaves like map HFind

Instances

Instances details
HFindMany ('[] :: [k]) (r :: [k]) ('[] :: [HNat]) Source # 
Instance details

Defined in Data.HList.RecordU

(HFind l r n, HFindMany ls r ns) => HFindMany (l ': ls :: [k]) (r :: [k]) (n ': ns) Source # 
Instance details

Defined in Data.HList.RecordU

hMapRU :: HMapCxt RecordU f x y => f -> RecordU x -> RecordU y Source #

hMap specialized to RecordU

unboxed :: forall x y f p. (Profunctor p, Functor f, RecordToRecordU x, RecordUToRecord y) => (RecordU x `p` f (RecordU y)) -> Record x `p` f (Record y) Source #

Iso (Record x) (Record y) (RecordU x) (RecordU y)

unboxed' :: forall p f (y :: [Type]) (n :: HNat). (Profunctor p, Functor f, RecordValues y, HList2List (RecordValuesR y) (GetElemTy y), KnownNat (HNat2Nat n), HLengthEq1 y n, HLengthEq2 y n, IArray UArray (GetElemTy y), SameLength' (HReplicateR n ()) y, HMapAux HList TaggedFn (RecordValuesR y) y) => p (RecordU y) (f (RecordU y)) -> p (Record y) (f (Record y)) Source #

Iso' (Record x) (RecordU x)

class RecordToRecordU x where Source #

Instances

Instances details
(RecordValues x, HList2List (RecordValuesR x) (GetElemTy x), HNat2Integral n, HLengthEq x n, IArray UArray (GetElemTy x)) => RecordToRecordU x Source # 
Instance details

Defined in Data.HList.RecordU

class RecordUToRecord x where Source #

Instances

Instances details
(HMapCxt HList TaggedFn (RecordValuesR x) x, IArray UArray (GetElemTy x), HList2List (RecordValuesR x) (GetElemTy x)) => RecordUToRecord x Source # 
Instance details

Defined in Data.HList.RecordU

definitions for doctest examples

type Bad = [Tagged "x" Double, Tagged "i" Int, Tagged "y" Double, Tagged "j" Int] Source #

bad :: Record Bad Source #

HasField instances

RecordUS
>>> let r = recordToRecordUS (sortForRecordUS bad)
>>> let s = recordToRecordUS bad
>>> let x = Label :: Label "x"
>>> let y = Label :: Label "y"
>>> let i = Label :: Label "i"
>>> let j = Label :: Label "j"
>>> (r .!. x, r .!. i, r .!. y, r .!. j)
(1.0,2,3.0,4)
>>> (s .!. x, s .!. i, s .!. y, s .!. j)
(1.0,2,3.0,4)
RecordU
>>> let t = recordToRecordU bad1
>>> (t .!. x, t .!. y)
(1.0,2.0)
>>> hUpdateAtLabel x 3 t .!. x
3.0

Implementation Details

data UnboxF Source #

Constructors

UnboxF 

Instances

Instances details
(hx ~ HList x, ux ~ RecordU x, RecordToRecordU x) => ApplyAB UnboxF hx ux Source # 
Instance details

Defined in Data.HList.RecordU

Methods

applyAB :: UnboxF -> hx -> ux Source #

data BoxF Source #

Constructors

BoxF 

Instances

Instances details
(ux ~ RecordU x, hx ~ HList x, RecordUToRecord x) => ApplyAB BoxF ux hx Source # 
Instance details

Defined in Data.HList.RecordU

Methods

applyAB :: BoxF -> ux -> hx Source #