HList-0.5.2.0: Heterogeneous lists
Safe HaskellNone
LanguageHaskell2010

Data.HList.TIP

Description

The HList library

(C) 2004, Oleg Kiselyov, Ralf Laemmel, Keean Schupke

Type-indexed products. The public interface is described in CommonMain#TIP

Synopsis

Documentation

class TransTIPM2 (b :: Bool) m arg op db where Source #

Methods

ttipM2 :: Proxy b -> (arg -> op) -> TIP db -> m (TIP db) Source #

Instances

Instances details
Fail (FieldNotFound op (TIP db)) => TransTIPM2 'False m arg op db Source # 
Instance details

Defined in Data.HList.TIP

Methods

ttipM2 :: Proxy 'False -> (arg -> op) -> TIP db -> m (TIP db) Source #

(HOccurs arg (TIP db), TransTIPM m op db) => TransTIPM2 'True m arg op db Source # 
Instance details

Defined in Data.HList.TIP

Methods

ttipM2 :: Proxy 'True -> (arg -> op) -> TIP db -> m (TIP db) Source #

class Monad m => TransTIPM1 (b :: Bool) (n :: HNat) m op db where Source #

Methods

ttipM1 :: Proxy b -> Proxy n -> op -> TIP db -> m (TIP db) Source #

Instances

Instances details
(Fail (FieldNotFound op (TIP db)), Monad m) => TransTIPM1 'False 'HZero m op db Source # 
Instance details

Defined in Data.HList.TIP

Methods

ttipM1 :: Proxy 'False -> Proxy 'HZero -> op -> TIP db -> m (TIP db) Source #

(Monad m, m ~ m', HTPupdateAtLabel TIP op op db) => TransTIPM1 'True n m (m' op) db Source # 
Instance details

Defined in Data.HList.TIP

Methods

ttipM1 :: Proxy 'True -> Proxy n -> m' op -> TIP db -> m (TIP db) Source #

(Monad m, HMember (Tagged arg arg) db b, TransTIPM2 b m arg op db) => TransTIPM1 'False ('HSucc n) m (arg -> op) db Source # 
Instance details

Defined in Data.HList.TIP

Methods

ttipM1 :: Proxy 'False -> Proxy ('HSucc n) -> (arg -> op) -> TIP db -> m (TIP db) Source #

class Monad m => TransTIPM m op db where Source #

In March 2010, Andrew Frank extended the problem for monadic operations. This is the monadic version of TIPTransform.hs in the present directory.

This is the TF implementation. When specifying the operation to perform over a TIP, we can leave it polymorphic over the monad. The type checker will instantiate the monad based on the context.

Methods

ttipM :: op -> TIP db -> m (TIP db) Source #

Instances

Instances details
(Monad m, HMember (Tagged op op) db b, Arity (m' op) n, TransTIPM1 b n m (m' op) db) => TransTIPM m (m' op) db Source # 
Instance details

Defined in Data.HList.TIP

Methods

ttipM :: m' op -> TIP db -> m (TIP db) Source #

class TransTIP2 (b :: Bool) arg op db where Source #

Methods

ttip2 :: Proxy b -> (arg -> op) -> TIP db -> TIP db Source #

Instances

Instances details
Fail (FieldNotFound arg (TIP db)) => TransTIP2 'False arg op db Source # 
Instance details

Defined in Data.HList.TIP

Methods

ttip2 :: Proxy 'False -> (arg -> op) -> TIP db -> TIP db Source #

(HOccurs arg (TIP db), TransTIP op db) => TransTIP2 'True arg op db Source # 
Instance details

Defined in Data.HList.TIP

Methods

ttip2 :: Proxy 'True -> (arg -> op) -> TIP db -> TIP db Source #

class TransTIP1 (b :: Bool) (n :: HNat) op db where Source #

Methods

ttip1 :: Proxy b -> Proxy n -> op -> TIP db -> TIP db Source #

Instances

Instances details
Fail (FieldNotFound notfun (TIP db)) => TransTIP1 'False 'HZero notfun db Source # 
Instance details

Defined in Data.HList.TIP

Methods

ttip1 :: Proxy 'False -> Proxy 'HZero -> notfun -> TIP db -> TIP db Source #

HTPupdateAtLabel TIP op op db => TransTIP1 'True n op db Source # 
Instance details

Defined in Data.HList.TIP

Methods

ttip1 :: Proxy 'True -> Proxy n -> op -> TIP db -> TIP db Source #

(HMember (Tagged arg arg) db b, TransTIP2 b arg op db) => TransTIP1 'False ('HSucc n) (arg -> op) db Source # 
Instance details

Defined in Data.HList.TIP

Methods

ttip1 :: Proxy 'False -> Proxy ('HSucc n) -> (arg -> op) -> TIP db -> TIP db Source #

class TransTIP op db where Source #

Transforming a TIP: applying to a TIP a (polyvariadic) function that takes arguments from a TIP and updates the TIP with the result.

In more detail: we have a typed-indexed collection TIP and we would like to apply a transformation function to it, whose argument types and the result type are all in the TIP. The function should locate its arguments based on their types, and update the TIP with the result. The function may have any number of arguments, including zero; the order of arguments should not matter.

The problem was posed by Andrew U. Frank on Haskell-Cafe, Sep 10, 2009. http://www.haskell.org/pipermail/haskell-cafe/2009-September/066217.html The problem is an interesting variation of the keyword argument problem.

Examples can be found in examples/TIPTransform.hs and examples/TIPTransformM.hs

Methods

ttip :: op -> TIP db -> TIP db Source #

Instances

Instances details
(HMember (Tagged op op) db b, Arity op n, TransTIP1 b n op db) => TransTIP op db Source # 
Instance details

Defined in Data.HList.TIP

Methods

ttip :: op -> TIP db -> TIP db Source #

type family Untag1 (x :: *) :: * Source #

Instances

Instances details
type Untag1 (Tagged k2 x) Source # 
Instance details

Defined in Data.HList.TIP

type Untag1 (Tagged k2 x) = x

type family UntagR (ta :: [*]) :: [*] Source #

Instances

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

Defined in Data.HList.TIP

type UntagR ('[] :: [Type]) = '[] :: [Type]
type UntagR (Tagged y y ': ys) Source # 
Instance details

Defined in Data.HList.TIP

type UntagR (Tagged y y ': ys) = y ': UntagR ys

type family TagR (a :: [*]) :: [*] Source #

Instances

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

Defined in Data.HList.TIP

type TagR ('[] :: [Type]) = '[] :: [Type]
type TagR (x ': xs) Source # 
Instance details

Defined in Data.HList.TIP

type TagR (x ': xs) = Tagged x x ': TagR xs

type UntagTag xs = (TagR (UntagR xs) ~ xs, TagUntagFD (UntagR xs) xs) Source #

Sometimes the type variables available have TagR already applied (ie the lists have elements like Tagged X X). Then this abbreviation is useful:

type TagUntag xs = TagUntagFD xs (TagR xs) Source #

class SameLength a ta => TagUntagFD a ta | a -> ta, ta -> a where Source #

TagR can also be used to avoid redundancy when defining types for TIC and TIP.

 type XShort = TagR [A,B,C,D]
 type XLong = [Tagged A A, Tagged B B, Tagged C C, Tagged D D]

an equivalent FD version, which is slightly better with respect to simplifying types containing type variables (in ghc-7.8 and 7.6): http://stackoverflow.com/questions/24110410/

With ghc-7.10 (http://ghc.haskell.org/trac/ghc/ticket/10009) the FD version is superior to the TF version:

class (UntagR (TagR a) ~ a) => TagUntag a where
    type TagR a :: [*]
    hTagSelf :: HList a -> HList (TagR a)
    hUntagSelf :: HList (TagR a) -> HList a

instance TagUntag '[] where
    type TagR '[] = '[]
    hTagSelf _ = HNil
    hUntagSelf _ = HNil

instance TagUntag xs => TagUntag (x ': xs) where
    type TagR (x ': xs) = Tagged x x ': TagR xs
    hTagSelf (HCons x xs) = Tagged x HCons hTagSelf xs
    hUntagSelf (HCons (Tagged x) xs) = x HCons hUntagSelf xs

type family UntagR (xs :: [*]) :: [*]
type instance UntagR '[] = '[]
type instance UntagR (x ': xs) = Untag1 x ': UntagR xs

Length information should flow backwards

>>> let len2 x = x `asTypeOf` (undefined :: HList '[a,b])
>>> let f = len2 $ hTagSelf (hReplicate Proxy ())
>>> :t f
f :: HList '[Tagged () (), Tagged () ()]

Methods

hTagSelf :: HList a -> HList ta Source #

hUntagSelf :: HList ta -> HList a Source #

Instances

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

Defined in Data.HList.TIP

Methods

hTagSelf :: HList '[] -> HList '[] Source #

hUntagSelf :: HList '[] -> HList '[] Source #

(TagUntagFD xs ys, txx ~ Tagged x x) => TagUntagFD (x ': xs) (txx ': ys) Source # 
Instance details

Defined in Data.HList.TIP

Methods

hTagSelf :: HList (x ': xs) -> HList (txx ': ys) Source #

hUntagSelf :: HList (txx ': ys) -> HList (x ': xs) Source #

class HAllTaggedEq (l :: [*]) Source #

Instances

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

Defined in Data.HList.TIP

(HAllTaggedEq l, tee ~ Tagged e e') => HAllTaggedEq (tee ': l) Source # 
Instance details

Defined in Data.HList.TIP

class (HAllTaggedEq l, HRLabelSet l) => HTypeIndexed (l :: [*]) Source #

this constraint ensures that a TIP created by mkTIP has no duplicates

Instances

Instances details
(HAllTaggedEq l, HRLabelSet l) => HTypeIndexed l Source # 
Instance details

Defined in Data.HList.TIP

newtype TIP (l :: [*]) Source #

TIPs are like Record, except element "i" of the list "l" has type Tagged e_i e_i

Constructors

TIP 

Fields

Instances

Instances details
TypeIndexed Record TIP Source # 
Instance details

Defined in Data.HList.TIC

Methods

typeIndexed :: forall p f (s :: [Type]) (t :: [Type]) (a :: [Type]) (b :: [Type]). (TypeIndexedCxt s t a b, Profunctor p, Functor f) => p (TIP (TagR a)) (f (TIP (TagR b))) -> p (Record s) (f (Record t)) Source #

(HUnzip TIP x y xy, HZipList xL yL xyL, lty ~ (HList xL -> HList yL -> HList xyL), Coercible lty (TIP x -> TIP y -> TIP xy), UntagR x ~ xL, UntagR y ~ yL, UntagR xy ~ xyL, UntagTag x, UntagTag y, UntagTag xy) => HZip TIP x y xy Source # 
Instance details

Defined in Data.HList.TIP

Methods

hZip :: TIP x -> TIP y -> TIP xy Source #

(HZipList xL yL xyL, lty ~ (HList xyL -> (HList xL, HList yL)), Coercible lty (TIP xy -> (TIP x, TIP y)), UntagR x ~ xL, TagR xL ~ x, UntagR y ~ yL, TagR yL ~ y, UntagR xy ~ xyL, TagR xyL ~ xy, SameLengths '[x, y, xy], UntagTag x, UntagTag y, UntagTag xy) => HUnzip TIP x y xy Source # 
Instance details

Defined in Data.HList.TIP

Methods

hUnzip :: TIP xy -> (TIP x, TIP y) Source #

(HDeleteAtLabel Record e v v', HTypeIndexed v') => HDeleteAtLabel TIP (e :: k) v v' Source # 
Instance details

Defined in Data.HList.TIP

Methods

hDeleteAtLabel :: Label e -> TIP v -> TIP v' Source #

LabelableTIPCxt x s t a b => Labelable (x :: k) TIP s t a b Source #

make a Lens' (TIP s) a.

tipyLens provides a Lens (TIP s) (TIP t) a b, which tends to need too many type annotations to be practical

Instance details

Defined in Data.HList.Labelable

Associated Types

type LabelableTy TIP :: LabeledOpticType Source #

Methods

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

HasField e (Record (x ': (y ': l))) e => HOccurs e (TIP (x ': (y ': l))) Source # 
Instance details

Defined in Data.HList.TIP

Methods

hOccurs :: TIP (x ': (y ': l)) -> e Source #

tee ~ Tagged e e => HOccurs e (TIP '[tee]) Source #

One occurrence and nothing is left

This variation provides an extra feature for singleton lists. That is, the result type is unified with the element in the list. Hence the explicit provision of a result type can be omitted.

Instance details

Defined in Data.HList.TIP

Methods

hOccurs :: TIP '[tee] -> e Source #

(HRLabelSet (Tagged e e ': l), HTypeIndexed l) => HExtend e (TIP l) Source # 
Instance details

Defined in Data.HList.TIP

Associated Types

type HExtendR e (TIP l) Source #

Methods

(.*.) :: e -> TIP l -> HExtendR e (TIP l) Source #

Bounded (HList r) => Bounded (TIP r) Source # 
Instance details

Defined in Data.HList.TIP

Methods

minBound :: TIP r #

maxBound :: TIP r #

Eq (HList a) => Eq (TIP a) Source # 
Instance details

Defined in Data.HList.TIP

Methods

(==) :: TIP a -> TIP a -> Bool #

(/=) :: TIP a -> TIP a -> Bool #

(TypeablePolyK xs, Typeable (HList xs), Data (HList xs)) => Data (TIP xs) Source # 
Instance details

Defined in Data.HList.Data

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TIP xs -> c (TIP xs) #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (TIP xs) #

toConstr :: TIP xs -> Constr #

dataTypeOf :: TIP xs -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (TIP xs)) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (TIP xs)) #

gmapT :: (forall b. Data b => b -> b) -> TIP xs -> TIP xs #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TIP xs -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TIP xs -> r #

gmapQ :: (forall d. Data d => d -> u) -> TIP xs -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> TIP xs -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> TIP xs -> m (TIP xs) #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TIP xs -> m (TIP xs) #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TIP xs -> m (TIP xs) #

Ord (HList r) => Ord (TIP r) Source # 
Instance details

Defined in Data.HList.TIP

Methods

compare :: TIP r -> TIP r -> Ordering #

(<) :: TIP r -> TIP r -> Bool #

(<=) :: TIP r -> TIP r -> Bool #

(>) :: TIP r -> TIP r -> Bool #

(>=) :: TIP r -> TIP r -> Bool #

max :: TIP r -> TIP r -> TIP r #

min :: TIP r -> TIP r -> TIP r #

HMapOut (HComp HShow HUntag) l String => Show (TIP l) Source # 
Instance details

Defined in Data.HList.TIP

Methods

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

show :: TIP l -> String #

showList :: [TIP l] -> ShowS #

Ix (HList r) => Ix (TIP r) Source # 
Instance details

Defined in Data.HList.TIP

Methods

range :: (TIP r, TIP r) -> [TIP r] #

index :: (TIP r, TIP r) -> TIP r -> Int #

unsafeIndex :: (TIP r, TIP r) -> TIP r -> Int #

inRange :: (TIP r, TIP r) -> TIP r -> Bool #

rangeSize :: (TIP r, TIP r) -> Int #

unsafeRangeSize :: (TIP r, TIP r) -> Int #

Semigroup (HList a) => Semigroup (TIP a) Source # 
Instance details

Defined in Data.HList.TIP

Methods

(<>) :: TIP a -> TIP a -> TIP a #

sconcat :: NonEmpty (TIP a) -> TIP a #

stimes :: Integral b => b -> TIP a -> TIP a #

Monoid (HList a) => Monoid (TIP a) Source # 
Instance details

Defined in Data.HList.TIP

Methods

mempty :: TIP a #

mappend :: TIP a -> TIP a -> TIP a #

mconcat :: [TIP a] -> TIP a #

(HUpdateAtLabel Record e' e r r', HTypeIndexed r', e ~ e') => HUpdateAtLabel TIP (e' :: Type) e r r' Source # 
Instance details

Defined in Data.HList.TIP

Methods

hUpdateAtLabel :: Label e' -> e -> TIP r -> TIP r' Source #

(e ~ e', HasField e (Record l) e') => HasField (e :: Type) (TIP l) e' Source # 
Instance details

Defined in Data.HList.TIP

Methods

hLookupByLabel :: Label e -> TIP l -> e' Source #

(HAppend (HList l) (HList l'), HTypeIndexed (HAppendListR l l')) => HAppend (TIP l) (TIP l') Source # 
Instance details

Defined in Data.HList.TIP

Methods

hAppend :: TIP l -> TIP l' -> HAppendR (TIP l) (TIP l') Source #

(HOccurs e (TIP l1), SubType (TIP l1) (TIP l2)) => SubType (TIP l1 :: Type) (TIP (e ': l2) :: Type) Source # 
Instance details

Defined in Data.HList.TIP

SubType (TIP l :: Type) (TIP ('[] :: [Type])) Source #

Subtyping for TIPs

Instance details

Defined in Data.HList.TIP

type LabelableTy TIP Source # 
Instance details

Defined in Data.HList.Labelable

type HExtendR e (TIP l) Source # 
Instance details

Defined in Data.HList.TIP

type HExtendR e (TIP l) = TIP (Tagged e e ': l)
type HAppendR (TIP l :: Type) (TIP l' :: Type) Source # 
Instance details

Defined in Data.HList.TIP

type HAppendR (TIP l :: Type) (TIP l' :: Type) = TIP (HAppendListR l l')

onRecord :: forall (l :: [Type]) (r :: [Type]). (HAllTaggedEq l, HLabelSet (LabelsOf l), HAllTaggedLV l) => (Record r -> Record l) -> TIP r -> TIP l Source #

tipyUpdate :: forall record v (r :: [Type]). (HUpdateAtLabel record v v r r, SameLength' r r) => v -> record r -> record r Source #

tipyProject :: forall (l :: [Type]) (ls :: [Type]) (t :: [Type]) (b :: [Type]) proxy. (HAllTaggedEq l, HLabelSet (LabelsOf l), HAllTaggedLV l, H2ProjectByLabels ls t l b) => proxy ls -> TIP t -> TIP l Source #

Use Labels to specify the first argument

tipyLens' :: forall a (t :: [Type]) f. (HasField a (Record t) a, HUpdateAtLabel2 a a t t, HAllTaggedEq t, HLabelSet (LabelsOf t), HAllTaggedLV t, SameLength' t t, SameLabels t t, Functor f) => (a -> f a) -> TIP t -> f (TIP t) Source #

provides a Lens' (TIP s) a. hLens' :: Label a -> Lens' (TIP s) a is another option.

tipyLens :: forall (n :: HNat) x (xs1 :: [Type]) (l1 :: [Type]) a1 (xs2 :: [Type]) (b :: Bool) a2 f. (HSplitAt1 ('[] :: [Type]) n (Tagged x x ': xs1) l1 (Tagged a1 a1 ': xs2), HAppendList1 l1 (Tagged a1 a1 ': xs2) (Tagged x x ': xs1), SameLength' (HReplicateR n ()) l1, HLengthEq1 l1 n, HLengthEq2 l1 n, HEq (Label a1) (Label x) b, HFind2 b (Label a1) (LabelsOf xs1) (Label x ': LabelsOf xs1) n, HAllTaggedEq (HAppendListR l1 (Tagged a2 a2 ': xs2)), HLabelSet (LabelsOf (HAppendListR l1 (Tagged a2 a2 ': xs2))), HAllTaggedLV (HAppendListR l1 (Tagged a2 a2 ': xs2)), HAppendList l1 (Tagged a2 a2 ': xs2), Functor f) => (a1 -> f a2) -> TIP (Tagged x x ': xs1) -> f (TIP (HAppendListR l1 (Tagged a2 a2 ': xs2))) Source #

provides a Lens (TIP s) (TIP t) a b

When using set (also known as .~), tipyLens' can address the ambiguity as to which field "a" should actually be updated.

tipyProject2 :: forall (ls :: [Type]) (r :: [Type]) (l1 :: [Type]) (l2 :: [Type]) proxy. (H2ProjectByLabels ls r l1 l2, HAllTaggedEq l1, HAllTaggedEq l2, HLabelSet (LabelsOf l1), HLabelSet (LabelsOf l2), HAllTaggedLV l1, HAllTaggedLV l2) => proxy ls -> TIP r -> (TIP l1, TIP l2) Source #

The same as tipyProject, except also return the types not requested in the proxy argument

tipHList :: forall p f (a1 :: [Type]) (ta :: [Type]) (a2 :: [Type]) (l :: [Type]). (Profunctor p, Functor f, TagUntagFD a1 ta, TagUntagFD a2 l) => p (HList a1) (f (HList a2)) -> p (TIP ta) (f (TIP l)) Source #

Iso (TIP (TagR a)) (TIP (TagR b)) (HList a) (HList b)

tipHList' :: forall p f (a :: [Type]) (l :: [Type]). (Profunctor p, Functor f, TagUntagFD a l) => p (HList a) (f (HList a)) -> p (TIP l) (f (TIP l)) Source #

Iso' (TIP (TagR s)) (HList a)

tipRecord :: forall p f (r :: [Type]) (l :: [Type]). (Profunctor p, Functor f) => p (Record r) (f (Record l)) -> p (TIP r) (f (TIP l)) Source #

Iso (TIP s) (TIP t) (Record s) (Record t)

typeIndexed may be more appropriate

tipRecord' :: forall p f (l :: [Type]). (Profunctor p, Functor f) => p (Record l) (f (Record l)) -> p (TIP l) (f (TIP l)) Source #

Iso' (TIP (TagR s)) (Record a)

hZipTIP :: forall (x :: [Type]) (y :: [Type]) (a :: [Type]) (l :: [Type]) (ta1 :: [Type]) (ta2 :: [Type]). (HZipList x y a, TagUntagFD a l, TagUntagFD x ta1, TagUntagFD y ta2) => TIP ta1 -> TIP ta2 -> TIP l Source #

specialization of hZip

hUnzipTIP :: forall (a1 :: [Type]) (a2 :: [Type]) (l1 :: [Type]) (l2 :: [Type]) (l3 :: [Type]) (ta :: [Type]). (HZipList a1 a2 l1, HAllTaggedEq l2, HAllTaggedEq l3, HLabelSet (LabelsOf l2), HLabelSet (LabelsOf l3), HAllTaggedLV l2, HAllTaggedLV l3, TagUntagFD l1 ta, TagUntagFD a1 l2, TagUntagFD a2 l3) => TIP ta -> (TIP l2, TIP l3) Source #

specialization of hUnzip