HList-0.5.0.0: Heterogeneous lists

Safe HaskellNone
LanguageHaskell2010

Data.HList.FakePrelude

Contents

Description

The HList library

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

Some very basic technology for faking dependent types in Haskell.

Synopsis

A heterogeneous apply operator

class Apply f a where Source #

simpler/weaker version where type information only propagates forward with this one. applyAB defined below, is more complicated / verbose to define, but it offers better type inference. Most uses have been converted to applyAB, so there is not much that can be done with Apply.

Minimal complete definition

apply

Associated Types

type ApplyR f a :: * Source #

Methods

apply :: f -> a -> ApplyR f a Source #

Instances

HLookupByHNat n l => Apply (FHLookupByHNat l) (Proxy HNat n) Source # 

Associated Types

type ApplyR (FHLookupByHNat l) (Proxy HNat n) :: * Source #

Apply (FHUProj sel ns) (HList l, Proxy HNat (HSucc n)) => Apply (Proxy Bool False, FHUProj sel ns) (HList ((:) * e l), Proxy HNat n) Source # 

Associated Types

type ApplyR (Proxy Bool False, FHUProj sel ns) (HList ((* ': e) l), Proxy HNat n) :: * Source #

Methods

apply :: (Proxy Bool False, FHUProj sel ns) -> (HList ((* ': e) l), Proxy HNat n) -> ApplyR (Proxy Bool False, FHUProj sel ns) (HList ((* ': e) l), Proxy HNat n) Source #

Apply (Proxy Bool True, FHUProj sel ns) (HList ((:) * e l), Proxy HNat n) Source # 

Associated Types

type ApplyR (Proxy Bool True, FHUProj sel ns) (HList ((* ': e) l), Proxy HNat n) :: * Source #

Methods

apply :: (Proxy Bool True, FHUProj sel ns) -> (HList ((* ': e) l), Proxy HNat n) -> ApplyR (Proxy Bool True, FHUProj sel ns) (HList ((* ': e) l), Proxy HNat n) Source #

((~) * ch (Proxy Bool (HBoolEQ sel (KMember n ns))), Apply (ch, FHUProj sel ns) (HList ((:) * e l), Proxy HNat n)) => Apply (FHUProj sel ns) (HList ((:) * e l), Proxy HNat n) Source # 

Associated Types

type ApplyR (FHUProj sel ns) (HList ((* ': e) l), Proxy HNat n) :: * Source #

Methods

apply :: FHUProj sel ns -> (HList ((* ': e) l), Proxy HNat n) -> ApplyR (FHUProj sel ns) (HList ((* ': e) l), Proxy HNat n) Source #

Apply (FHUProj sel ns) (HList ([] *), n) Source # 

Associated Types

type ApplyR (FHUProj sel ns) (HList [*], n) :: * Source #

Methods

apply :: FHUProj sel ns -> (HList [*], n) -> ApplyR (FHUProj sel ns) (HList [*], n) Source #

Polymorphic functions are not first-class in haskell. An example of this is:

f op = (op (1 :: Double), op (1 :: Int))
RankNTypes

One solution is to enable `-XRankNTypes` and then write a type signature which might be `f :: (forall a. Num a => a -> a)`. This does not work in the context of HList, since we want to use functions that do not necessarily fall into the pattern of (forall a. c a => a -> a).

MultipleArguments

Another solution is to rewrite op to look like

f op1 op2 = (op1 (1:: Double), op2 (1 :: Int))

In some sense this approach works (see HZip), but the result is constrained to as many function applications as you are willing to write (ex. a function that works for records of six entries would look like hBuild f f f f f f).

Defunctionalization

Therefore the selected solution is to write an instance of ApplyAB for a data type that takes the place of the original function. In other words,

data Fn = Fn
instance ApplyAB Fn a b where applyAB Fn a = actual_fn a

Normally you would have been able to pass around the definition actual_fn.

Type inference / Local functional dependencies

Note that class ApplyAB has three parameters and no functional dependencies. Instances should be written in the style:

instance (int ~ Int, double ~ Double) => ApplyAB Fn int double
 where applyAB _ = fromIntegral

rather than the more natural

instance ApplyAB Fn Int Double

The first instance allows types to be inferred as if we had class ApplyAB a b c | a -> b c, while the second instance only matches if ghc already knows that it needs ApplyAB Fn Int Double. Since applyAB Fn :: Int -> Double has a monomorphic type, this trimmed down example does not really make sense because applyAB (fromIntegral :: Int -> Double) is exactly the same. Nontheless, the other uses of ApplyAB follow this pattern, and the benefits are seen when the type of applyAB Fn has at least one type variable.

Additional explanation can be found in local functional dependencies

AmbiguousTypes

Note that ghc only allows AllowAmbiguousTypes when a type signature is provided. Thus expressions such as:

data AddJust = AddJust
instance (y ~ Maybe x) => ApplyAB AddJust x y where
   applyAB _ x = Just x

twoJustsBad = hMap AddJust . hMap AddJust -- ambiguous type

Are not accepted without a type signature that references the intermediate "b":

twoJusts :: forall r a b c. (HMapCxt r AddJust a b, HMapCxt r AddJust b c) =>
       r a -> r c
twoJusts a = hMap AddJust (hMap AddJust a :: r b)

An apply class with functional dependencies

class ApplyAB' f a b | f a -> b, f b -> a

Or with equivalent type families

class (GetB f a ~ b, GetA f b ~ a) => ApplyAB' f a b

would not require an annotation for twoJusts. However, not all instances of ApplyAB will satisfy those functional dependencies, and thus the number of classes would proliferate. Furthermore, inference does not have to be in one direction only, as the example of HMap shows.

class ApplyAB f a b where Source #

No constraints on result and argument types

Minimal complete definition

applyAB

Methods

applyAB :: f -> a -> b Source #

Instances

(~) * (Tagged k t x) tx => ApplyAB HUntag tx x Source # 

Methods

applyAB :: HUntag -> tx -> x Source #

((~) * f1 (a -> b -> c), (~) * f2 (b -> a -> c)) => ApplyAB HFlip f1 f2 Source # 

Methods

applyAB :: HFlip -> f1 -> f2 Source #

((~) * y y', (~) * fg (x -> y, y' -> z), (~) * r (x -> z)) => ApplyAB Comp fg r Source # 

Methods

applyAB :: Comp -> fg -> r Source #

((~) * String string, Show a) => ApplyAB HShow a string Source # 

Methods

applyAB :: HShow -> a -> string Source #

((~) * String string, Read a) => ApplyAB HRead string a Source # 

Methods

applyAB :: HRead -> string -> a Source #

((~) * io (IO ()), Show x) => ApplyAB HPrint x io Source # 

Methods

applyAB :: HPrint -> x -> io Source #

((~) * aa (a, a), Semigroup a) => ApplyAB UncurrySappend aa a Source # 

Methods

applyAB :: UncurrySappend -> aa -> a Source #

((~) * aa (a, a), Monoid a) => ApplyAB UncurryMappend aa a Source # 

Methods

applyAB :: UncurryMappend -> aa -> a Source #

((~) * x (Proxy * y), Monoid y) => ApplyAB ConstMempty x y Source # 

Methods

applyAB :: ConstMempty -> x -> y Source #

(~) * hJustA (HJust a) => ApplyAB HFromJust hJustA a Source # 

Methods

applyAB :: HFromJust -> hJustA -> a Source #

((~) * x (e, HList l), (~) * y (HList ((:) * e l))) => ApplyAB FHCons x y Source # 

Methods

applyAB :: FHCons -> x -> y Source #

(~) * tx (Tagged k t x) => ApplyAB TaggedFn x tx Source # 

Methods

applyAB :: TaggedFn -> x -> tx Source #

((~) * x (Tagged k l v), (~) * y (HList ((:) * (Label k l) ((:) * v ([] *))))) => ApplyAB TaggedToKW x y Source # 

Methods

applyAB :: TaggedToKW -> x -> y Source #

(HZip3 a b c, (~) * x (HList a, HList b), (~) * y (HList c)) => ApplyAB HZipF x y Source # 

Methods

applyAB :: HZipF -> x -> y Source #

((~) * x (Tagged k t (Maybe e), [Variant v]), (~) * y [Variant ((:) * (Tagged k t e) v)], MkVariant k t e ((:) * (Tagged k t e) v)) => ApplyAB HMaybiedToVariantFs x y Source # 

Methods

applyAB :: HMaybiedToVariantFs -> x -> y Source #

(~) * y (Tagged k t (Maybe e)) => ApplyAB ConstTaggedNothing x y Source # 

Methods

applyAB :: ConstTaggedNothing -> x -> y Source #

((~) * mx (Maybe x), (~) * my (Maybe y), HCast y x) => ApplyAB HCastF mx my Source # 

Methods

applyAB :: HCastF -> mx -> my Source #

((~) * ee (e, e), Eq e, (~) * bool Bool) => ApplyAB UncurryEq ee bool Source # 

Methods

applyAB :: UncurryEq -> ee -> bool Source #

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

Methods

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

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

Methods

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

(~) * e' e => ApplyAB HRmTag (e, t) e' Source # 

Methods

applyAB :: HRmTag -> (e, t) -> e' Source #

((~) * y (ReadP x), Read x) => ApplyAB ReadElement (Proxy * x) y Source # 

Methods

applyAB :: ReadElement -> Proxy * x -> y Source #

(Read v, ShowLabel k l, (~) * x (Tagged k l v), (~) * (ReadP x) y) => ApplyAB ReadComponent (Proxy * x) y Source # 

Methods

applyAB :: ReadComponent -> Proxy * x -> y Source #

(~) * hJustA (HJust a) => ApplyAB (HJust t) a hJustA Source #

HJust () is a placeholder for a function that applies the HJust constructor

Methods

applyAB :: HJust t -> a -> hJustA Source #

(ApplyAB f (x, y) z, (~) * mz (m z), (~) * mxy (m x, m y), Applicative m) => ApplyAB (LiftA2 f) mxy mz Source # 

Methods

applyAB :: LiftA2 f -> mxy -> mz Source #

((~) * x (t a), (~) * y (t b), Functor t, ApplyAB f a b) => ApplyAB (HFmap f) x y Source # 

Methods

applyAB :: HFmap f -> x -> y Source #

(Monad m, ApplyAB f x fx, (~) * fx (m ()), (~) * pair (x, m ()), ApplyAB f x (m ())) => ApplyAB (HSeq f) pair fx Source # 

Methods

applyAB :: HSeq f -> pair -> fx Source #

((~) * hxs (HList xs), (~) * hxxs (HList ((:) * x xs))) => ApplyAB (FHCons2 x) hxs hxxs Source # 

Methods

applyAB :: FHCons2 x -> hxs -> hxxs Source #

(~) * et (e, t) => ApplyAB (HAddTag t) e et Source # 

Methods

applyAB :: HAddTag t -> e -> et Source #

((~) * l [e'], ApplyAB f e e', (~) * el (e, l)) => ApplyAB (Mapcar f) el l Source # 

Methods

applyAB :: Mapcar f -> el -> l Source #

(HMapCxt HList f a b, (~) * as (HList a), (~) * bs (HList b)) => ApplyAB (HMapL f) as bs Source # 

Methods

applyAB :: HMapL f -> as -> bs Source #

(HMapCxt r f a b, (~) * as (r a), (~) * bs (r b)) => ApplyAB (HMap f) as bs Source # 

Methods

applyAB :: HMap f -> as -> bs Source #

(HMapCxt Record f x y, (~) * rx (Record x), (~) * ry (Record y)) => ApplyAB (HMapR f) rx ry Source # 

Methods

applyAB :: HMapR f -> rx -> ry Source #

((~) * vx (Variant x), (~) * vy (Variant y), HMapAux Variant (HFmap f) x y, SameLength * * x y) => ApplyAB (HMapV f) vx vy Source #

apply a function to all values that could be in the variant.

Methods

applyAB :: HMapV f -> vx -> vy Source #

(Data b, (~) * x (t, c (b -> r)), (~) * y (c r)) => ApplyAB (GunfoldK c) x y Source # 

Methods

applyAB :: GunfoldK c -> x -> y Source #

(Data d, (~) * (c (d -> b), d) x, (~) * (c b) y) => ApplyAB (GfoldlK c) x y Source # 

Methods

applyAB :: GfoldlK c -> x -> y Source #

ApplyAB f e e' => ApplyAB (MapCar f) (e, HList l) (HList ((:) * e' l)) Source # 

Methods

applyAB :: MapCar f -> (e, HList l) -> HList ((* ': e') l) Source #

((~) * x' x, (~) * y' y) => ApplyAB (x' -> y') x y Source #

note this function will only be available at a single type (that is, hMap succ will only work on HList that contain only one type)

Methods

applyAB :: (x' -> y') -> x -> y Source #

(ApplyAB f a b, ApplyAB g b c) => ApplyAB (HComp g f) a c Source # 

Methods

applyAB :: HComp g f -> a -> c Source #

(FunCxt k1 cxt b, (~) * (FunApp k2 geta b) a) => ApplyAB (Fun' k1 k2 cxt geta) a b Source # 

Methods

applyAB :: Fun' k1 k2 cxt geta -> a -> b Source #

(FunCxt k1 cxt a, (~) * (FunApp k2 getb a) b) => ApplyAB (Fun k1 k2 cxt getb) a b Source # 

Methods

applyAB :: Fun k1 k2 cxt getb -> a -> b Source #

Fun can be used instead of writing a new instance of ApplyAB. Refer to the definition/source for the the most concise explanation. A more wordy explanation is given below:

A type signature needs to be provided on Fun to make it work. Depending on the kind of the parameters to Fun, a number of different results happen.

ex1

A list of kind [* -> Constraint] produces those constraints on the argument type:

>>> :set -XDataKinds
>>> let plus1f x = if x < 5 then x+1 else 5
>>> let plus1 = Fun plus1f :: Fun '[Num, Ord] '()
>>> :t applyAB plus1
applyAB plus1 :: (Num b, Ord b) => b -> b
>>> let xs = [1 .. 8]
>>> map (applyAB plus1) xs == map plus1f xs
True

Also note the use of '() to signal that the result type is the same as the argument type.

A single constraint can also be supplied:

>>> let succ1 = Fun succ :: Fun Enum '()
>>> :t applyAB succ1
applyAB succ1 :: Enum b => b -> b
>>> let just = Fun Just :: Fun '[] Maybe
>>> :t applyAB just
applyAB just :: a -> Maybe a

data Fun (cxt :: k1) (getb :: k2) Source #

Constructors

Fun (forall a. FunCxt cxt a => a -> FunApp getb a) 

Instances

(FunCxt k1 cxt a, (~) * (FunApp k2 getb a) b) => ApplyAB (Fun k1 k2 cxt getb) a b Source # 

Methods

applyAB :: Fun k1 k2 cxt getb -> a -> b Source #

data Fun' (cxt :: k1) (geta :: k2) Source #

see Fun. The only difference here is that the argument type is calculated from the result type.

>>> let rd = Fun' read :: Fun' Read String
>>> :t applyAB rd
applyAB rd :: Read b => [Char] -> b
>>> let fromJust' = Fun' (\(Just a) -> a) :: Fun' '[] Maybe
>>> :t applyAB fromJust'
applyAB fromJust' :: Maybe b -> b

Note this use of Fun' means we don't have to get the b out of Maybe b,

Constructors

Fun' (forall b. FunCxt cxt b => FunApp geta b -> b) 

Instances

(FunCxt k1 cxt b, (~) * (FunApp k2 geta b) a) => ApplyAB (Fun' k1 k2 cxt geta) a b Source # 

Methods

applyAB :: Fun' k1 k2 cxt geta -> a -> b Source #

type family FunApp (fns :: k) a Source #

Instances

type FunApp * fn a Source # 
type FunApp * fn a = fn
type FunApp () fn a Source # 
type FunApp () fn a = a
type FunApp (* -> *) fn a Source # 
type FunApp (* -> *) fn a = fn a

type family FunCxt (cxts :: k) a :: Constraint Source #

Instances

type FunCxt * cxt a Source # 
type FunCxt * cxt a = (~) * cxt a
type FunCxt () cxt a Source # 
type FunCxt () cxt a = ()
type FunCxt [k] ([] k) a Source # 
type FunCxt [k] ([] k) a = ()
type FunCxt [* -> Constraint] ((:) (* -> Constraint) x xs) a Source # 
type FunCxt [* -> Constraint] ((:) (* -> Constraint) x xs) a = (x a, FunCxt [* -> Constraint] xs a)
type FunCxt (* -> Constraint) cxt a Source # 
type FunCxt (* -> Constraint) cxt a = cxt a

Simple useful instances of Apply

data HPrint Source #

print. An alternative implementation could be:

>>> let hPrint = Fun print :: Fun Show (IO ())

This produces:

>>> :t applyAB hPrint
applyAB hPrint :: Show a => a -> IO ()

Constructors

HPrint 

Instances

((~) * io (IO ()), Show x) => ApplyAB HPrint x io Source # 

Methods

applyAB :: HPrint -> x -> io Source #

data HRead Source #

read

>>> applyAB HRead "5.0" :: Double
5.0

Constructors

HRead 

Instances

((~) * String string, Read a) => ApplyAB HRead string a Source # 

Methods

applyAB :: HRead -> string -> a Source #

data HShow Source #

show

Constructors

HShow 

Instances

((~) * String string, Show a) => ApplyAB HShow a string Source # 

Methods

applyAB :: HShow -> a -> string Source #

data HComp g f Source #

Compose two instances of ApplyAB

>>> applyAB (HComp HRead HShow) (5::Double) :: Double
5.0

Constructors

HComp g f
g . f

Instances

(ApplyAB f a b, ApplyAB g b c) => ApplyAB (HComp g f) a c Source # 

Methods

applyAB :: HComp g f -> a -> c Source #

data Comp Source #

app Comp (f,g) = g . f. Works like:

>>> applyAB Comp (succ, pred) 'a'
'a'
>>> applyAB Comp (toEnum :: Int -> Char, fromEnum) 10
10

Note that defaulting will sometimes give you the wrong thing

used to work (with associated types calculating result/argument types)
>>> applyAB Comp (fromEnum, toEnum) 'a'
*** Exception: Prelude.Enum.().toEnum: bad argument

Constructors

Comp 

Instances

((~) * y y', (~) * fg (x -> y, y' -> z), (~) * r (x -> z)) => ApplyAB Comp fg r Source # 

Methods

applyAB :: Comp -> fg -> r Source #

newtype HSeq x Source #

((a,b) -> f a >> b)

Constructors

HSeq x 

Instances

(Monad m, ApplyAB f x fx, (~) * fx (m ()), (~) * pair (x, m ()), ApplyAB f x (m ())) => ApplyAB (HSeq f) pair fx Source # 

Methods

applyAB :: HSeq f -> pair -> fx Source #

data HFlip Source #

Constructors

HFlip 

Instances

((~) * f1 (a -> b -> c), (~) * f2 (b -> a -> c)) => ApplyAB HFlip f1 f2 Source # 

Methods

applyAB :: HFlip -> f1 -> f2 Source #

newtype HFmap f Source #

Constructors

HFmap f 

Instances

((~) * x (t a), (~) * y (t b), Functor t, ApplyAB f a b) => ApplyAB (HFmap f) x y Source # 

Methods

applyAB :: HFmap f -> x -> y Source #

newtype LiftA2 f Source #

Constructors

LiftA2 f 

Instances

(ApplyAB f (x, y) z, (~) * mz (m z), (~) * mxy (m x, m y), Applicative m) => ApplyAB (LiftA2 f) mxy mz Source # 

Methods

applyAB :: LiftA2 f -> mxy -> mz Source #

data HUntag Source #

Constructors

HUntag 

Instances

(~) * (Tagged k t x) tx => ApplyAB HUntag tx x Source # 

Methods

applyAB :: HUntag -> tx -> x Source #

Proxy

data Label l Source #

A special Proxy for record labels, polykinded

Constructors

Label 

Instances

(HasField k l (Record r) u, HasFieldPath needJust ls u v) => HasFieldPath needJust ((:) * (Label k l) ls) (Record r) v Source # 

Methods

hLookupByLabelPath1 :: Proxy Bool needJust -> Label [*] ((* ': Label k l) ls) -> Record r -> v Source #

(HasField k l (Variant r) (Maybe u), HasFieldPath True ls u (Maybe v)) => HasFieldPath needJust ((:) * (Label k l) ls) (Variant r) (Maybe v) Source # 

Methods

hLookupByLabelPath1 :: Proxy Bool needJust -> Label [*] ((* ': Label k l) ls) -> Variant r -> Maybe v Source #

(~) * (Label k t) (Label Symbol t') => SameLabels * Symbol (Label k t) t' Source # 
HEqBy * k HLeFn x y b => HEqBy * * HLeFn (Label k x) (Label k y) b Source # 
(~) * (Label k2 t) (Label k1 t') => SameLabels * * (Label k2 t) (Label k1 t') Source # 
(~) * (Label k2 t) (Label k1 t') => SameLabels * * (Label k2 t) (Tagged k1 t' a) Source # 
(~) * (Label k t) (Label * (Lbl ix ns n)) => SameLabels * * (Label k t) (Lbl ix ns n) Source # 
((~) * lv (Tagged k l v), HUnzip (Proxy [*]) ls vs lvs) => HUnzip (Proxy [*]) ((:) * (Label k l) ls) ((:) * v vs) ((:) * lv lvs) Source # 

Methods

hUnzip :: Proxy [*] ((* ': lv) lvs) -> (Proxy [*] ((* ': Label k l) ls), Proxy [*] ((* ': v) vs)) Source #

Show desc => Show (Label * (Lbl x ns desc)) # 

Methods

showsPrec :: Int -> Label * (Lbl x ns desc) -> ShowS #

show :: Label * (Lbl x ns desc) -> String #

showList :: [Label * (Lbl x ns desc)] -> ShowS #

HExtend (Label * (Lbl n ns desc)) (Proxy [Symbol] ((:) Symbol x xs)) Source #

Mixing two label kinds means we have to include Label:

>>> let r = label3 .*. label6 .*. emptyProxy
>>> :t r
r :: Proxy '[Label (Lbl 'HZero () ()), Label "6"]

Associated Types

type HExtendR (Label * (Lbl n ns desc)) (Proxy [Symbol] ((Symbol ': x) xs)) :: * Source #

Methods

(.*.) :: Label * (Lbl n ns desc) -> Proxy [Symbol] ((Symbol ': x) xs) -> HExtendR (Label * (Lbl n ns desc)) (Proxy [Symbol] ((Symbol ': x) xs)) Source #

HExtend (Label * (Lbl n ns desc)) (Proxy [*] ((:) * (Lbl n' ns' desc') xs)) Source #

If possible, Label is left off:

>>> let q = label3 .*. label3 .*. emptyProxy
>>> :t q
q :: Proxy '[Lbl 'HZero () (), Lbl 'HZero () ()]

Associated Types

type HExtendR (Label * (Lbl n ns desc)) (Proxy [*] ((* ': Lbl n' ns' desc') xs)) :: * Source #

Methods

(.*.) :: Label * (Lbl n ns desc) -> Proxy [*] ((* ': Lbl n' ns' desc') xs) -> HExtendR (Label * (Lbl n ns desc)) (Proxy [*] ((* ': Lbl n' ns' desc') xs)) Source #

HExtend (Label k x) (Proxy [*] ([] *)) Source #

to keep types shorter, .*. used with Proxy avoids producing a Proxy :: Proxy '[Label x,Label y,Label z] if Proxy :: Proxy '[x,y,z] is not a kind error (as it is when mixing Label6 and Label3 labels).

ghc-7.6 does not accept Proxy ('[] :: [k]) so for now require k ~ *

Associated Types

type HExtendR (Label k x) (Proxy [*] [*]) :: * Source #

Methods

(.*.) :: Label k x -> Proxy [*] [*] -> HExtendR (Label k x) (Proxy [*] [*]) Source #

ToSym * (a b c) x => EnsureLabel (a b c) (Label Symbol x) Source #

get the Label out of a LabeledTo (ie. `foobar when using HListPP).

Methods

toLabel :: a b c -> Label Symbol x Source #

EnsureLabel (Proxy k x) (Label k x) Source # 

Methods

toLabel :: Proxy k x -> Label k x Source #

EnsureLabel (Label k x) (Label k x) Source # 

Methods

toLabel :: Label k x -> Label k x Source #

(Labelable k1 x r s t a b, (~) * j (p a (f b)), (~) * k2 (p (r s) (f (r t))), (~) LabeledOpticType ty (LabelableTy r), LabeledOpticP ty p, LabeledOpticF ty f, LabeledOpticTo k1 ty x ((->) LiftedRep LiftedRep), LabelablePath xs i j) => LabelablePath ((:) * (Label k1 x) xs) i k2 Source # 

Methods

hLens'Path :: Label [*] ((* ': Label k1 x) xs) -> i -> k2 Source #

type UnLabel a proxy ((:) * (Label a x) xs) Source # 
type UnLabel a proxy ((:) * (Label a x) xs) = (:) a x (UnLabel a proxy xs)
type ZipTagged * ((:) * (Label k t) ts) ((:) * v vs) Source # 
type ZipTagged * ((:) * (Label k t) ts) ((:) * v vs) = (:) * (Tagged k t v) (ZipTagged * ts vs)
type HExtendR (Label * (Lbl n ns desc)) (Proxy [*] ((:) * (Lbl n' ns' desc') xs)) Source # 
type HExtendR (Label * (Lbl n ns desc)) (Proxy [*] ((:) * (Lbl n' ns' desc') xs)) = Proxy [*] ((:) * (Lbl n ns desc) ((:) * (Lbl n' ns' desc') xs))
type HExtendR (Label * (Lbl n ns desc)) (Proxy [Symbol] ((:) Symbol x xs)) Source # 
type HExtendR (Label * (Lbl n ns desc)) (Proxy [Symbol] ((:) Symbol x xs)) = Proxy [*] ((:) * (Label * (Lbl n ns desc)) (MapLabel Symbol ((:) Symbol x xs)))
type HExtendR (Label Nat y) (Proxy [Symbol] ((:) Symbol x xs)) Source # 
type HExtendR (Label Nat y) (Proxy [Symbol] ((:) Symbol x xs)) = Proxy [*] ((:) * (Label Nat y) (MapLabel Symbol ((:) Symbol x xs)))
type HExtendR (Label Nat y) (Proxy [*] ((:) * x xs)) Source # 
type HExtendR (Label Nat y) (Proxy [*] ((:) * x xs)) = Proxy [*] ((:) * (Label Nat y) (MapLabel * ((:) * x xs)))
type HExtendR (Label Nat y) (Proxy [Nat] ((:) Nat x xs)) Source # 
type HExtendR (Label Nat y) (Proxy [Nat] ((:) Nat x xs)) = Proxy [Nat] ((:) Nat y ((:) Nat x xs))
type HExtendR (Label Symbol y) (Proxy [Nat] ((:) Nat x xs)) Source # 
type HExtendR (Label Symbol y) (Proxy [Nat] ((:) Nat x xs)) = Proxy [*] ((:) * (Label Symbol y) (MapLabel Nat ((:) Nat x xs)))
type HExtendR (Label Symbol y) (Proxy [*] ((:) * x xs)) Source # 
type HExtendR (Label Symbol y) (Proxy [*] ((:) * x xs)) = Proxy [*] ((:) * (Label Symbol y) (MapLabel * ((:) * x xs)))
type HExtendR (Label Symbol y) (Proxy [Symbol] ((:) Symbol x xs)) Source # 
type HExtendR (Label Symbol y) (Proxy [Symbol] ((:) Symbol x xs)) = Proxy [Symbol] ((:) Symbol y ((:) Symbol x xs))
type HExtendR (Label k x) (Proxy [*] ([] *)) Source # 
type HExtendR (Label k x) (Proxy [*] ([] *)) = Proxy [k] ((:) k x ([] k))
type LabelsOf ((:) * (Label k l) r) Source # 
type LabelsOf ((:) * (Label k l) r) = (:) * (Label k l) (LabelsOf r)

class ShowLabel l where Source #

Minimal complete definition

showLabel

Methods

showLabel :: Label l -> String Source #

Instances

Show desc => ShowLabel * (Lbl x ns desc) Source #

Equality on labels (descriptions are ignored) Use generic instance

Show label

Methods

showLabel :: Label (Lbl x ns desc) l -> String Source #

Booleans

GHC already lifts booleans, defined as

data Bool = True | False

to types: Bool becomes kind and True and False (also denoted by 'True and 'False) become nullary type constructors.

The above line is equivalent to

data HTrue
data HFalse
class HBool x
instance HBool HTrue
instance HBool HFalse

Value-level proxies

Conjunction

type family HAnd (t1 :: Bool) (t2 :: Bool) :: Bool Source #

Instances

type HAnd False t Source # 
type HAnd False t = False
type HAnd True t Source # 
type HAnd True t = t

hAnd :: Proxy t1 -> Proxy t2 -> Proxy (HAnd t1 t2) Source #

demote to values

Disjunction

type family HOr (t1 :: Bool) (t2 :: Bool) :: Bool Source #

Instances

type HOr False t Source # 
type HOr False t = t
type HOr True t Source # 
type HOr True t = True

hOr :: Proxy t1 -> Proxy t2 -> Proxy (HOr t1 t2) Source #

demote to values

Compare with the original code based on functional dependencies:

class (HBool t, HBool t', HBool t'') => HOr t t' t'' | t t' -> t''
 where
  hOr :: t -> t' -> t''
instance HOr HFalse HFalse HFalse
 where
  hOr _ _ = hFalse
instance HOr HTrue HFalse HTrue
 where
  hOr _ _ = hTrue
instance HOr HFalse HTrue HTrue
 where
  hOr _ _ = hTrue
instance HOr HTrue HTrue HTrue
 where
  hOr _ _ = hTrue

type family HNot (x :: Bool) :: Bool Source #

Instances

type HNot False Source # 
type HNot False = True
type HNot True Source # 
type HNot True = False

class HNotFD (b :: Bool) (nb :: Bool) | b -> nb, nb -> b Source #

as compared with HNot this version is injective

hNot :: HNotFD a notA => Proxy a -> Proxy notA Source #

class HCond (t :: Bool) x y z | t x y -> z where Source #

Minimal complete definition

hCond

Methods

hCond :: Proxy t -> x -> y -> z Source #

Instances

HCond False x y y Source # 

Methods

hCond :: Proxy Bool False -> x -> y -> y Source #

HCond True x y x Source # 

Methods

hCond :: Proxy Bool True -> x -> y -> x Source #

Boolean equivalence

Naturals

data HNat Source #

The data type to be lifted to the type level

Constructors

HZero 
HSucc HNat 

Instances

(~) [*] xxs ([] *) => HLengthEq1 HNat xxs HZero Source # 
(HLengthEq xs n, (~) [*] xxs ((:) * x xs)) => HLengthEq1 HNat xxs (HSucc n) Source # 
(~) HNat zero HZero => HLengthEq2 HNat ([] *) zero Source # 
HFindMany k ([] k) r ([] HNat) Source # 
(HLengthEq xs n, (~) HNat sn (HSucc n)) => HLengthEq2 HNat ((:) * x xs) sn Source # 
(HFind k l r n, HFindMany k ls r ns) => HFindMany k ((:) k l ls) r ((:) HNat n ns) Source # 
HNats2Integrals ([] HNat) Source # 

Methods

hNats2Integrals :: Integral i => Proxy [HNat] [HNat] -> [i] Source #

(~) Bool (HLe x y) b => HEqBy * HNat HLeFn x y b Source # 
HLookupByHNat n l => Apply (FHLookupByHNat l) (Proxy HNat n) Source # 

Associated Types

type ApplyR (FHLookupByHNat l) (Proxy HNat n) :: * Source #

Apply (FHUProj sel ns) (HList l, Proxy HNat (HSucc n)) => Apply (Proxy Bool False, FHUProj sel ns) (HList ((:) * e l), Proxy HNat n) Source # 

Associated Types

type ApplyR (Proxy Bool False, FHUProj sel ns) (HList ((* ': e) l), Proxy HNat n) :: * Source #

Methods

apply :: (Proxy Bool False, FHUProj sel ns) -> (HList ((* ': e) l), Proxy HNat n) -> ApplyR (Proxy Bool False, FHUProj sel ns) (HList ((* ': e) l), Proxy HNat n) Source #

Apply (Proxy Bool True, FHUProj sel ns) (HList ((:) * e l), Proxy HNat n) Source # 

Associated Types

type ApplyR (Proxy Bool True, FHUProj sel ns) (HList ((* ': e) l), Proxy HNat n) :: * Source #

Methods

apply :: (Proxy Bool True, FHUProj sel ns) -> (HList ((* ': e) l), Proxy HNat n) -> ApplyR (Proxy Bool True, FHUProj sel ns) (HList ((* ': e) l), Proxy HNat n) Source #

((~) * ch (Proxy Bool (HBoolEQ sel (KMember n ns))), Apply (ch, FHUProj sel ns) (HList ((:) * e l), Proxy HNat n)) => Apply (FHUProj sel ns) (HList ((:) * e l), Proxy HNat n) Source # 

Associated Types

type ApplyR (FHUProj sel ns) (HList ((* ': e) l), Proxy HNat n) :: * Source #

Methods

apply :: FHUProj sel ns -> (HList ((* ': e) l), Proxy HNat n) -> ApplyR (FHUProj sel ns) (HList ((* ': e) l), Proxy HNat n) Source #

(HNats2Integrals ns, HNat2Integral n) => HNats2Integrals ((:) HNat n ns) Source # 

Methods

hNats2Integrals :: Integral i => Proxy [HNat] ((HNat ': n) ns) -> [i] Source #

(HNat2Integral n, (~) * (HLookupByHNatR n u) le, (~) * le (Tagged k l e), IArray UArray e, (~) * e (GetElemTy u)) => HLookupByHNatUS1 (Left HNat HNat t) n u us le Source # 

Methods

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

HLookupByHNatUS t us e => HLookupByHNatUS1 (Right HNat HNat t) n u us e Source # 
type KMember n ([] HNat) Source # 
type KMember n ([] HNat) = False
type KMember n ((:) HNat n1 l) Source # 
type KMember n ((:) HNat n1 l) = HOr (HNatEq n n1) (KMember n l)
type ApplyR (FHLookupByHNat l) (Proxy HNat n) Source # 
type ApplyR (Proxy Bool False, FHUProj sel ns) (HList ((:) * e l), Proxy HNat n) Source # 
type ApplyR (Proxy Bool False, FHUProj sel ns) (HList ((:) * e l), Proxy HNat n) = ApplyR (FHUProj sel ns) (HList l, Proxy HNat (HSucc n))
type ApplyR (Proxy Bool True, FHUProj sel ns) (HList ((:) * e l), Proxy HNat n) Source # 
type ApplyR (Proxy Bool True, FHUProj sel ns) (HList ((:) * e l), Proxy HNat n) = HJust (e, (HList l, Proxy HNat (HSucc n)))
type ApplyR (FHUProj sel ns) (HList ((:) * e l), Proxy HNat n) Source # 
type ApplyR (FHUProj sel ns) (HList ((:) * e l), Proxy HNat n) = ApplyR (Proxy Bool (HBoolEQ sel (KMember n ns)), FHUProj sel ns) (HList ((:) * e l), Proxy HNat n)
type HNats ((:) * (Proxy HNat n) l) Source # 
type HNats ((:) * (Proxy HNat n) l) = (:) HNat n (HNats l)

hSucc :: Proxy (n :: HNat) -> Proxy (HSucc n) Source #

class HNat2Integral (n :: HNat) where Source #

Minimal complete definition

hNat2Integral

Methods

hNat2Integral :: Integral i => Proxy n -> i Source #

Instances

type family HNat2Nat (n :: HNat) :: Nat Source #

Instances

type HNat2Nat HZero Source # 
type HNat2Nat HZero = 0
type HNat2Nat (HSucc n) Source # 
type HNat2Nat (HSucc n) = (+) 1 (HNat2Nat n)

class HNats2Integrals (ns :: [HNat]) where Source #

Minimal complete definition

hNats2Integrals

Methods

hNats2Integrals :: Integral i => Proxy ns -> [i] Source #

Instances

HNats2Integrals ([] HNat) Source # 

Methods

hNats2Integrals :: Integral i => Proxy [HNat] [HNat] -> [i] Source #

(HNats2Integrals ns, HNat2Integral n) => HNats2Integrals ((:) HNat n ns) Source # 

Methods

hNats2Integrals :: Integral i => Proxy [HNat] ((HNat ': n) ns) -> [i] Source #

type family HNatEq (t1 :: HNat) (t2 :: HNat) :: Bool Source #

Equality on natural numbers (eventually to be subsumed by the universal polykinded HEq)

Instances

type HNatEq HZero HZero Source # 
type HNatEq HZero (HSucc n) Source # 
type HNatEq HZero (HSucc n) = False
type HNatEq (HSucc n) HZero Source # 
type HNatEq (HSucc n) HZero = False
type HNatEq (HSucc n) (HSucc n') Source # 
type HNatEq (HSucc n) (HSucc n') = HNatEq n n'

type family HLt (x :: HNat) (y :: HNat) :: Bool Source #

Less than

Instances

type HLt HZero HZero Source # 
type HLt HZero (HSucc n) Source # 
type HLt HZero (HSucc n) = True
type HLt (HSucc n) HZero Source # 
type HLt (HSucc n) HZero = False
type HLt (HSucc n) (HSucc n') Source # 
type HLt (HSucc n) (HSucc n') = HLt n n'

hLt :: Proxy x -> Proxy y -> Proxy (HLt x y) Source #

type family HLe (x :: HNat) (y :: HNat) :: Bool Source #

Less than or equal to

Instances

type HLe HZero HZero Source # 
type HLe (HSucc x) y Source # 
type HLe (HSucc x) y = HLt x y

hLe :: Proxy x -> Proxy y -> Proxy (HLe x y) Source #

type family HDiv2 (x :: HNat) :: HNat Source #

HDiv2 x behaves like x div 2

Instances

type HDiv2 HZero Source # 
type HDiv2 (HSucc HZero) Source # 
type HDiv2 (HSucc (HSucc a)) Source # 
type HDiv2 (HSucc (HSucc a)) = HSucc (HDiv2 a)

Maybies

We cannot use lifted Maybe since the latter are not populated

data HNothing Source #

Constructors

HNothing 

Instances

Show HNothing Source # 
HUnfoldFD p HNothing ([] *) Source # 

Methods

hUnfold' :: p -> HNothing -> HList [*] Source #

FromHJust l => FromHJust ((:) * HNothing l) Source # 

Associated Types

type FromHJustR ((* ': HNothing) l :: [*]) :: [*] Source #

Methods

fromHJust :: HList ((* ': HNothing) l) -> HList (FromHJustR ((* ': HNothing) l)) Source #

type HUnfoldR p HNothing Source # 
type HUnfoldR p HNothing = [] *
type FromHJustR ((:) * HNothing l) Source # 
type FromHJustR ((:) * HNothing l) = FromHJustR l

newtype HJust x Source #

Constructors

HJust x 

Instances

(Apply p s, HUnfoldFD p (ApplyR p s) z) => HUnfoldFD p (HJust (e, s)) ((:) * e z) Source # 

Methods

hUnfold' :: p -> HJust (e, s) -> HList ((* ': e) z) Source #

Show x => Show (HJust x) Source # 

Methods

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

show :: HJust x -> String #

showList :: [HJust x] -> ShowS #

(~) * hJustA (HJust a) => ApplyAB (HJust t) a hJustA Source #

HJust () is a placeholder for a function that applies the HJust constructor

Methods

applyAB :: HJust t -> a -> hJustA Source #

FromHJust l => FromHJust ((:) * (HJust e) l) Source # 

Associated Types

type FromHJustR ((* ': HJust e) l :: [*]) :: [*] Source #

Methods

fromHJust :: HList ((* ': HJust e) l) -> HList (FromHJustR ((* ': HJust e) l)) Source #

type HUnfoldR p (HJust (e, s)) Source # 
type HUnfoldR p (HJust (e, s)) = (:) * e (HUnfoldR p (ApplyR p s))
type FromHJustR ((:) * (HJust e) l) Source # 
type FromHJustR ((:) * (HJust e) l) = (:) * e (FromHJustR l)

Polykinded Equality for types

class HEq (x :: k) (y :: k) (b :: Bool) | x y -> b Source #

We have to use Functional dependencies for now, for the sake of the generic equality.

type HEqK (x :: k1) (y :: k2) (b :: Bool) = HEq (Proxy x) (Proxy y) b Source #

Equality for types that may have different kinds. This definition allows operations on Record [Tagged "x" a, Tagged 2 b] to work as expected.

hEq :: HEq x y b => x -> y -> Proxy b Source #

class HEqByFn f => HEqBy (f :: t) (x :: k) (y :: k) (b :: Bool) | f x y -> b Source #

this class generalizes HEq by allowing the choice of f to allow equating only part of x and y

Instances

(~) 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 k2 k1 f y x b => HEqBy * k1 (HDown k2 f) x y b Source # 
(HEqBy k2 k1 le y x b1, (~) Bool (HNot b1) b2) => HEqBy * k1 (HNeq k2 le) x y b2 Source # 
((~) * txv (Tagged k2 x v), (~) * tyw (Tagged k1 y w), HEq * v w b) => HEqBy * * EqTagValue txv tyw 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.

class HEqByFn f Source #

Every instance of this class should have an instance of HEqBy

Arity

type Arity f n = (ArityFwd f n, ArityRev f n) Source #

class ArityFwd (f :: *) (n :: HNat) | f -> n Source #

calculate the number of arguments a function can take

class ArityRev (f :: *) (n :: HNat) Source #

given the number of arguments a function can take, make sure the function type actually matches

Instances

ArityRev f HZero Source # 
((~) * xf (x -> f), ArityRev f n) => ArityRev xf (HSucc n) Source # 

Staged equality

Type-safe cast -- no longer need. We use a a ~ b

Cast

class HCast x y where Source #

Named after cast, which behaves the same at runtime. One difference is that there is a HCast instance for every type, while Typeable instances can be missing sometimes.

Minimal complete definition

hCast

Methods

hCast :: x -> Maybe y Source #

Instances

(HEq * x y b, HCast1 b x y) => HCast x y Source # 

Methods

hCast :: x -> Maybe y Source #

class HCast1 (b :: Bool) x y where Source #

helper for HCast

Minimal complete definition

hCast1

Methods

hCast1 :: Proxy b -> x -> Maybe y Source #

Instances

HCast1 False x y Source # 

Methods

hCast1 :: Proxy Bool False -> x -> Maybe y Source #

(~) * x y => HCast1 True x y Source # 

Methods

hCast1 :: Proxy Bool True -> x -> Maybe y Source #

Error messages

class Fail (x :: k) Source #

A class without instances for explicit failure.

Note that with ghc>=8.0, `x :: TypeError` which is formatted properly. Otherwise x is made of nested (left-associated) promoted tuples. For example:

(x ~ '( '( '("the", Int), "is wrong") ) ) :: ((,) Symbol *, Symbol)

Therefore code that works across ghc-7.6 through ghc-8.0 needs to use ErrText, ErrShowType, :<>:, :$$: to construct the type x.

type ErrText x = Text x Source #

use the alias ErrText to prevent conflicts with Data.Text

GHC.TypeLits.:<>: and GHC.TypeLits.:$$: are re-exported

Error messages used elsewhere

type FieldNotFound key collection = (ErrText "key" :<>: ErrShowType key) :$$: (ErrText "could not be found in" :<>: ErrShowType collection) Source #

type ExcessFieldFound key collection = (ErrText "found field" :<>: ErrShowType key) :$$: (ErrText "when it should be absent from" :<>: ErrShowType collection) Source #

type HNatIndexTooLarge (nat :: HNat) (r :: [k] -> *) (xs :: [k]) = ((ErrText "0-based index" :<>: ErrShowType (HNat2Nat nat)) :<>: ErrText "is too large for collection") :$$: ErrShowType (r xs) Source #

type ExtraField x = ErrText "extra field" :<>: ErrShowType x Source #

type TypeablePolyK (a :: k) = Typeable a Source #

Constraining Lists

Length

class SameLength' (es1 :: [k]) (es2 :: [m]) Source #

Ensure two lists have the same length. We do case analysis on the first one (hence the type must be known to the type checker). In contrast, the second list may be a type variable.

Instances

(~) [m] es2 ([] m) => SameLength' k m ([] k) es2 Source # 
(SameLength' k m xs ys, (~) [m] es2 ((:) m y ys)) => SameLength' k m ((:) k x xs) es2 Source # 

class (SameLength' x y, SameLength' y x) => SameLength (x :: [k]) (y :: [m]) where Source #

symmetrical version of SameLength'. Written as a class instead of

type SameLength a b = (SameLength' a b, SameLength' b a)

since ghc expands type synonyms, but not classes (and it seems to have the same result)

Methods

sameLength :: (r x `p` f (q y)) -> r x `p` f (q y) Source #

SameLength x y => Equality (r x) (q y) (r x) (q y)

used like simple, except it restricts the type-level lists involved to have the same length, without fixing the type of container or the elements in the list.

Instances

(SameLength' k m x y, SameLength' m k y x) => SameLength k m x y Source # 

Methods

sameLength :: p (r x) (f (q y)) -> p (r x) (f (q y)) Source #

asLengthOf :: SameLength x y => r x -> s y -> r x Source #

type family SameLengths (xs :: [[k]]) :: Constraint Source #

Instances

type SameLengths k ([] [k]) Source # 
type SameLengths k ([] [k]) = ()
type SameLengths k ((:) [k] x ([] [k])) Source # 
type SameLengths k ((:) [k] x ([] [k])) = ()
type SameLengths k ((:) [k] x ((:) [k] y ys)) Source # 
type SameLengths k ((:) [k] x ((:) [k] y ys)) = (SameLength k k x y, SameLengths k ((:) [k] y ys))

Labels

class SameLabels (x :: k) (y :: m) Source #

Instances

SameLabels * m (Label Symbol t) s => SameLabels Symbol m t s Source # 
(~) * (Label k t) (Label Symbol t') => SameLabels * Symbol (Label k t) t' Source # 
SameLabels * m (Label k t) s => SameLabels * m (Tagged k t a) s Source # 
SameLabels [k1] [k2] ([] k1) ([] k2) Source # 
SameLabels [k] [a] ([] k) ((:) a x xs) Source # 
(~) * (Label k2 t) (Label k1 t') => SameLabels * * (Label k2 t) (Label k1 t') Source # 
(~) * (Label k2 t) (Label k1 t') => SameLabels * * (Label k2 t) (Tagged k1 t' a) Source # 
(~) * (Label k t) (Label * (Lbl ix ns n)) => SameLabels * * (Label k t) (Lbl ix ns n) Source # 
SameLabels [a] [k] ((:) a x xs) ([] k) Source # 
(SameLabels a2 a1 x y, SameLabels [a2] [a1] xs ys) => SameLabels [a2] [a1] ((:) a2 x xs) ((:) a1 y ys) Source # 

sameLabels :: SameLabels x y => p (r x) (f (q y)) -> p (r x) (f (q y)) Source #

sameLabels constrains the type of an optic, such that the labels (t in Tagged t a) are the same. x or y may have more elements than the other, in which case the elements at the end of the longer list do not have their labels constrained.

see also sameLength

A list has only Tagged values

class HAllTaggedLV (ps :: [*]) Source #

The Record, Variant, TIP, TIC type constructors only make sense when they are applied to an instance of this class

Instances

HAllTaggedLV ([] *) Source # 
(HAllTaggedLV xs, (~) * x (Tagged k t v)) => HAllTaggedLV ((:) * x xs) Source # 

type family ZipTagged (ts :: [k]) (vs :: [*]) :: [*] Source #

see Data.HList.Record.zipTagged

Instances

type ZipTagged k ([] k) ([] *) Source # 
type ZipTagged k ([] k) ([] *) = [] *
type ZipTagged Symbol ((:) Symbol t ts) ((:) * v vs) Source # 
type ZipTagged Symbol ((:) Symbol t ts) ((:) * v vs) = (:) * (Tagged Symbol t v) (ZipTagged Symbol ts vs)
type ZipTagged * ((:) * (Label k t) ts) ((:) * v vs) Source # 
type ZipTagged * ((:) * (Label k t) ts) ((:) * v vs) = (:) * (Tagged k t v) (ZipTagged * ts vs)
type ZipTagged * ((:) * (Lbl ix ns n) ts) ((:) * v vs) Source # 
type ZipTagged * ((:) * (Lbl ix ns n) ts) ((:) * v vs) = (:) * (Tagged * (Lbl ix ns n) v) (ZipTagged * ts vs)

re-exports

module Data.Proxy

class Monoid a where #

The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following laws:

  • mappend mempty x = x
  • mappend x mempty = x
  • mappend x (mappend y z) = mappend (mappend x y) z
  • mconcat = foldr mappend mempty

The method names refer to the monoid of lists under concatenation, but there are many other instances.

Some types can be viewed as a monoid in more than one way, e.g. both addition and multiplication on numbers. In such cases we often define newtypes and make those instances of Monoid, e.g. Sum and Product.

Minimal complete definition

mempty, mappend

Methods

mempty :: a #

Identity of mappend

mappend :: a -> a -> a #

An associative operation

mconcat :: [a] -> a #

Fold a list using the monoid. For most types, the default definition for mconcat will be used, but the function is included in the class definition so that an optimized version can be provided for specific types.

Instances

Monoid Ordering

Since: 2.1

Monoid ()

Since: 2.1

Methods

mempty :: () #

mappend :: () -> () -> () #

mconcat :: [()] -> () #

Monoid All

Since: 2.1

Methods

mempty :: All #

mappend :: All -> All -> All #

mconcat :: [All] -> All #

Monoid Any

Since: 2.1

Methods

mempty :: Any #

mappend :: Any -> Any -> Any #

mconcat :: [Any] -> Any #

Monoid Doc 

Methods

mempty :: Doc #

mappend :: Doc -> Doc -> Doc #

mconcat :: [Doc] -> Doc #

Monoid [a]

Since: 2.1

Methods

mempty :: [a] #

mappend :: [a] -> [a] -> [a] #

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

Monoid a => Monoid (Maybe a)

Lift a semigroup into Maybe forming a Monoid according to http://en.wikipedia.org/wiki/Monoid: "Any semigroup S may be turned into a monoid simply by adjoining an element e not in S and defining e*e = e and e*s = s = s*e for all s ∈ S." Since there used to be no "Semigroup" typeclass providing just mappend, we use Monoid instead.

Since: 2.1

Methods

mempty :: Maybe a #

mappend :: Maybe a -> Maybe a -> Maybe a #

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

Monoid a => Monoid (IO a)

Since: 4.9.0.0

Methods

mempty :: IO a #

mappend :: IO a -> IO a -> IO a #

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

(Ord a, Bounded a) => Monoid (Min a)

Since: 4.9.0.0

Methods

mempty :: Min a #

mappend :: Min a -> Min a -> Min a #

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

(Ord a, Bounded a) => Monoid (Max a)

Since: 4.9.0.0

Methods

mempty :: Max a #

mappend :: Max a -> Max a -> Max a #

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

Monoid m => Monoid (WrappedMonoid m)

Since: 4.9.0.0

Semigroup a => Monoid (Option a)

Since: 4.9.0.0

Methods

mempty :: Option a #

mappend :: Option a -> Option a -> Option a #

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

Monoid a => Monoid (Identity a) 

Methods

mempty :: Identity a #

mappend :: Identity a -> Identity a -> Identity a #

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

Monoid a => Monoid (Dual a)

Since: 2.1

Methods

mempty :: Dual a #

mappend :: Dual a -> Dual a -> Dual a #

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

Monoid (Endo a)

Since: 2.1

Methods

mempty :: Endo a #

mappend :: Endo a -> Endo a -> Endo a #

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

Num a => Monoid (Sum a)

Since: 2.1

Methods

mempty :: Sum a #

mappend :: Sum a -> Sum a -> Sum a #

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

Num a => Monoid (Product a)

Since: 2.1

Methods

mempty :: Product a #

mappend :: Product a -> Product a -> Product a #

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

Monoid (First a)

Since: 2.1

Methods

mempty :: First a #

mappend :: First a -> First a -> First a #

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

Monoid (Last a)

Since: 2.1

Methods

mempty :: Last a #

mappend :: Last a -> Last a -> Last a #

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

Monoid (Seq a) 

Methods

mempty :: Seq a #

mappend :: Seq a -> Seq a -> Seq a #

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

Monoid (Predicate a) 
Monoid (Comparison a) 
Monoid (Equivalence a) 
Monoid (Doc a) 

Methods

mempty :: Doc a #

mappend :: Doc a -> Doc a -> Doc a #

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

(HProxies a, HMapCxt HList ConstMempty (AddProxy [*] a) a, HZip HList a a aa, HMapCxt HList UncurryMappend aa a) => Monoid (HList a) #

Analogous to the Monoid instance for tuples

>>> import Data.Monoid
>>> mempty :: HList '[(), All, [Int]]
H[(),All {getAll = True},[]]
>>> mappend (hBuild "a") (hBuild "b") :: HList '[String]
H["ab"]

Methods

mempty :: HList a #

mappend :: HList a -> HList a -> HList a #

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

Monoid (HList r) => Monoid (Record r) # 

Methods

mempty :: Record r #

mappend :: Record r -> Record r -> Record r #

mconcat :: [Record r] -> Record r #

(Monoid x, Monoid (Variant ((:) * a b))) => Monoid (Variant ((:) * (Tagged k t x) ((:) * a b))) # 

Methods

mempty :: Variant ((* ': Tagged k t x) ((* ': a) b)) #

mappend :: Variant ((* ': Tagged k t x) ((* ': a) b)) -> Variant ((* ': Tagged k t x) ((* ': a) b)) -> Variant ((* ': Tagged k t x) ((* ': a) b)) #

mconcat :: [Variant ((* ': Tagged k t x) ((* ': a) b))] -> Variant ((* ': Tagged k t x) ((* ': a) b)) #

(Unvariant ((:) * (Tagged k t x) ([] *)) x, Monoid x) => Monoid (Variant ((:) * (Tagged k t x) ([] *))) # 

Methods

mempty :: Variant ((* ': Tagged k t x) [*]) #

mappend :: Variant ((* ': Tagged k t x) [*]) -> Variant ((* ': Tagged k t x) [*]) -> Variant ((* ': Tagged k t x) [*]) #

mconcat :: [Variant ((* ': Tagged k t x) [*])] -> Variant ((* ': Tagged k t x) [*]) #

Monoid (HList a) => Monoid (TIP a) # 

Methods

mempty :: TIP a #

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

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

Monoid (Variant l) => Monoid (TIC l) # 

Methods

mempty :: TIC l #

mappend :: TIC l -> TIC l -> TIC l #

mconcat :: [TIC l] -> TIC l #

Monoid b => Monoid (a -> b)

Since: 2.1

Methods

mempty :: a -> b #

mappend :: (a -> b) -> (a -> b) -> a -> b #

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

(Monoid a, Monoid b) => Monoid (a, b)

Since: 2.1

Methods

mempty :: (a, b) #

mappend :: (a, b) -> (a, b) -> (a, b) #

mconcat :: [(a, b)] -> (a, b) #

Monoid (Proxy k s)

Since: 4.7.0.0

Methods

mempty :: Proxy k s #

mappend :: Proxy k s -> Proxy k s -> Proxy k s #

mconcat :: [Proxy k s] -> Proxy k s #

Monoid a => Monoid (Op a b) 

Methods

mempty :: Op a b #

mappend :: Op a b -> Op a b -> Op a b #

mconcat :: [Op a b] -> Op a b #

(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c)

Since: 2.1

Methods

mempty :: (a, b, c) #

mappend :: (a, b, c) -> (a, b, c) -> (a, b, c) #

mconcat :: [(a, b, c)] -> (a, b, c) #

Alternative f => Monoid (Alt * f a)

Since: 4.8.0.0

Methods

mempty :: Alt * f a #

mappend :: Alt * f a -> Alt * f a -> Alt * f a #

mconcat :: [Alt * f a] -> Alt * f a #

ArrowPlus p => Monoid (Tambara p a b) 

Methods

mempty :: Tambara p a b #

mappend :: Tambara p a b -> Tambara p a b -> Tambara p a b #

mconcat :: [Tambara p a b] -> Tambara p a b #

(Semigroup a, Monoid a) => Monoid (Tagged k s a) 

Methods

mempty :: Tagged k s a #

mappend :: Tagged k s a -> Tagged k s a -> Tagged k s a #

mconcat :: [Tagged k s a] -> Tagged k s a #

(Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d)

Since: 2.1

Methods

mempty :: (a, b, c, d) #

mappend :: (a, b, c, d) -> (a, b, c, d) -> (a, b, c, d) #

mconcat :: [(a, b, c, d)] -> (a, b, c, d) #

(Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e)

Since: 2.1

Methods

mempty :: (a, b, c, d, e) #

mappend :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e) #

mconcat :: [(a, b, c, d, e)] -> (a, b, c, d, e) #

type family Any k0 :: k0 where ... #

The type constructor Any is type to which you can unsafely coerce any lifted type, and back. More concretely, for a lifted type t and value x :: t, -- unsafeCoerce (unsafeCoerce x :: Any) :: t is equivalent to x.