Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
The HList library
(C) 2004, Oleg Kiselyov, Ralf Laemmel, Keean Schupke
Some very basic technology for faking dependent types in Haskell.
Synopsis
- data ErrorMessage
- type family ZipTagged (ts :: [k]) (vs :: [*]) :: [*]
- class HAllTaggedLV (ps :: [*])
- class SameLabels (x :: k) (y :: m)
- type family SameLengths (xs :: [[k]]) :: Constraint
- class (SameLength' x y, SameLength' y x) => SameLength (x :: [k]) (y :: [m]) where
- sameLength :: (r x `p` f (q y)) -> r x `p` f (q y)
- class SameLength' (es1 :: [k]) (es2 :: [m])
- type TypeablePolyK (a :: k) = Typeable a
- type ExtraField x = ErrText "extra field" :<>: ErrShowType x
- type HNatIndexTooLarge (nat :: HNat) (r :: [k] -> *) (xs :: [k]) = ((ErrText "0-based index" :<>: ErrShowType (HNat2Nat nat)) :<>: ErrText "is too large for collection") :$$: ErrShowType (r xs)
- type ExcessFieldFound key collection = (ErrText "found field" :<>: ErrShowType key) :$$: (ErrText "when it should be absent from" :<>: ErrShowType collection)
- type FieldNotFound key collection = (ErrText "key" :<>: ErrShowType key) :$$: (ErrText "could not be found in" :<>: ErrShowType collection)
- type ErrShowType x = ShowType x
- type ErrText x = Text x
- class Fail (x :: k)
- class HCast1 (b :: Bool) x y where
- class HCast x y where
- class ArityRev (f :: *) (n :: HNat)
- class ArityFwd (f :: *) (n :: HNat) | f -> n
- type Arity f n = (ArityFwd f n, ArityRev f n)
- class HEqByFn f
- class HEqByFn f => HEqBy (f :: t) (x :: k) (y :: k) (b :: Bool) | f x y -> b
- type HEqK (x :: k1) (y :: k2) (b :: Bool) = HEq (Proxy x) (Proxy y) b
- class HEq (x :: k) (y :: k) (b :: Bool) | x y -> b
- newtype HJust x = HJust x
- data HNothing = HNothing
- type family HDiv2 (x :: HNat) :: HNat
- type family HLe (x :: HNat) (y :: HNat) :: Bool
- type family HLt (x :: HNat) (y :: HNat) :: Bool
- type family HNatEq (t1 :: HNat) (t2 :: HNat) :: Bool
- class HNats2Integrals (ns :: [HNat]) where
- hNats2Integrals :: Integral i => Proxy ns -> [i]
- type family HNat2Nat (n :: HNat) :: Nat
- class HNat2Integral (n :: HNat) where
- hNat2Integral :: Integral i => Proxy n -> i
- data HNat
- type family HBoolEQ (t1 :: Bool) (t2 :: Bool) :: Bool
- class HCond (t :: Bool) x y z | t x y -> z where
- class HNotFD (b :: Bool) (nb :: Bool) | b -> nb, nb -> b
- type family HNot (x :: Bool) :: Bool
- type family HOr (t1 :: Bool) (t2 :: Bool) :: Bool
- type family HAnd (t1 :: Bool) (t2 :: Bool) :: Bool
- class ShowLabel l where
- data Label l = Label
- data HUntag = HUntag
- newtype LiftA2 f = LiftA2 f
- newtype HFmap f = HFmap f
- data HFlip = HFlip
- newtype HSeq x = HSeq x
- data Comp = Comp
- data HComp g f = HComp g f
- data HShow = HShow
- data HRead = HRead
- data HPrint = HPrint
- type family FunCxt (cxts :: k) a :: Constraint
- type family FunApp (fns :: k) a
- data Fun' (cxt :: k1) (geta :: k2) = Fun' (forall b. FunCxt cxt b => FunApp geta b -> b)
- data Fun (cxt :: k1) (getb :: k2) = Fun (forall a. FunCxt cxt a => a -> FunApp getb a)
- class ApplyAB f a b where
- applyAB :: f -> a -> b
- class Apply f a where
- labelToProxy :: Label l -> Proxy l
- hTrue :: Proxy True
- hFalse :: Proxy False
- hAnd :: Proxy t1 -> Proxy t2 -> Proxy (HAnd t1 t2)
- hOr :: Proxy t1 -> Proxy t2 -> Proxy (HOr t1 t2)
- hNot :: HNotFD a notA => Proxy a -> Proxy notA
- hZero :: Proxy HZero
- hSucc :: Proxy (n :: HNat) -> Proxy (HSucc n)
- hPred :: Proxy (HSucc n) -> Proxy n
- hLt :: Proxy x -> Proxy y -> Proxy (HLt x y)
- hLe :: Proxy x -> Proxy y -> Proxy (HLe x y)
- hEq :: HEq x y b => x -> y -> Proxy b
- asLengthOf :: SameLength x y => r x -> s y -> r x
- sameLabels :: SameLabels x y => p (r x) (f (q y)) -> p (r x) (f (q y))
- module Data.Proxy
- module Data.Tagged
- class Semigroup a => Monoid a where
- type family Any :: k where ...
Documentation
data ErrorMessage #
A description of a custom type error.
ErrorMessage :<>: ErrorMessage infixl 6 | Put two pieces of error message next to each other. |
ErrorMessage :$$: ErrorMessage infixl 5 | Stack two pieces of error message on top of each other. |
Instances
(TypeError x :: Constraint) => Fail (x :: ErrorMessage) Source # | |
Defined in Data.HList.FakePrelude |
type family ZipTagged (ts :: [k]) (vs :: [*]) :: [*] Source #
see Data.HList.Record.zipTagged
Instances
type ZipTagged ('[] :: [k]) ('[] :: [Type]) Source # | |
Defined in Data.HList.FakePrelude | |
type ZipTagged (t ': ts :: [Symbol]) (v ': vs) Source # | |
Defined in Data.HList.FakePrelude | |
type ZipTagged (Label t ': ts :: [Type]) (v ': vs) Source # | |
type ZipTagged (Lbl ix ns n ': ts :: [Type]) (v ': vs) Source # | |
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 ('[] :: [Type]) Source # | |
Defined in Data.HList.FakePrelude | |
(HAllTaggedLV xs, x ~ Tagged t v) => HAllTaggedLV (x ': xs) Source # | |
Defined in Data.HList.FakePrelude |
class SameLabels (x :: k) (y :: m) Source #
Instances
type family SameLengths (xs :: [[k]]) :: Constraint Source #
Instances
type SameLengths ('[] :: [[k]]) Source # | |
Defined in Data.HList.FakePrelude type SameLengths ('[] :: [[k]]) = () | |
type SameLengths (x ': (y ': ys) :: [[k]]) Source # | |
Defined in Data.HList.FakePrelude | |
type SameLengths ('[x] :: [[k]]) Source # | |
Defined in Data.HList.FakePrelude type SameLengths ('[x] :: [[k]]) = () |
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)
Nothing
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' x y, SameLength' y x) => SameLength (x :: [k]) (y :: [m]) Source # | |
Defined in Data.HList.FakePrelude sameLength :: forall {k1} {k2} {k3} p (r :: [k0] -> k1) (f :: k3 -> k2) (q :: [m0] -> k3). p (r x) (f (q y)) -> p (r x) (f (q y)) Source # |
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
es2 ~ ('[] :: [m]) => SameLength' ('[] :: [k]) (es2 :: [m]) Source # | |
Defined in Data.HList.FakePrelude | |
(SameLength' xs ys, es2 ~ (y ': ys)) => SameLength' (x ': xs :: [k]) (es2 :: [m]) Source # | |
Defined in Data.HList.FakePrelude |
type TypeablePolyK (a :: k) = Typeable a Source #
type ExtraField x = ErrText "extra field" :<>: ErrShowType x 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 ExcessFieldFound key collection = (ErrText "found field" :<>: ErrShowType key) :$$: (ErrText "when it should be absent from" :<>: ErrShowType collection) Source #
type FieldNotFound key collection = (ErrText "key" :<>: ErrShowType key) :$$: (ErrText "could not be found in" :<>: ErrShowType collection) Source #
type ErrShowType x = ShowType x Source #
type ErrText x = Text x Source #
use the alias ErrText to prevent conflicts with Data.Text
GHC.TypeLits.:<>: and GHC.TypeLits.:$$: are re-exported
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.
Instances
(TypeError x :: Constraint) => Fail (x :: ErrorMessage) Source # | |
Defined in Data.HList.FakePrelude |
class ArityRev (f :: *) (n :: HNat) Source #
given the number of arguments a function can take, make sure the function type actually matches
class ArityFwd (f :: *) (n :: HNat) | f -> n Source #
calculate the number of arguments a function can take
Every instance of this class should have an instance of HEqBy
Instances
HEqByFn HLeFn Source # | |
Defined in Data.HList.HSort | |
HEqByFn EqTagValue Source # | |
Defined in Data.HList.RecordU | |
HEqByFn a => HEqByFn (HDown a :: Type) Source # | |
Defined in Data.HList.HSort | |
HEqByFn a => HEqByFn (HNeq a :: Type) Source # | |
Defined in Data.HList.HSort |
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
HLe x y ~ b => HEqBy HLeFn (x :: HNat) (y :: HNat) b Source # | |
Defined in Data.HList.HSort | |
(HEq (CmpSymbol x y) 'GT nb, HNot nb ~ b) => HEqBy HLeFn (x :: Symbol) (y :: Symbol) b Source # | only in ghc >= 7.7
|
Defined in Data.HList.HSort | |
(txv ~ Tagged x v, tyw ~ Tagged y w, HEq v w b) => HEqBy EqTagValue (txv :: Type) (tyw :: Type) b Source # | |
Defined in Data.HList.RecordU | |
(x <=? y) ~ b => HEqBy HLeFn (x :: k) (y :: k) b Source # | only in ghc >= 7.7 |
Defined in Data.HList.HSort | |
HEqBy HLeFn x y b => HEqBy HLeFn (Label x :: Type) (Label y :: Type) b Source # | |
Defined in Data.HList.HSort | |
HEqBy HLeFn x y b => HEqBy HLeFn (Proxy x :: Type) (Proxy y :: Type) b Source # | |
Defined in Data.HList.HSort | |
(HEqBy HLeFn n m b, ns ~ ns') => HEqBy HLeFn (Lbl n ns desc :: Type) (Lbl m ns' desc' :: Type) b Source # | Data.HList.Label3 labels can only be compared if they belong to the same namespace. |
Defined in Data.HList.HSort | |
HEqBy HLeFn x y b => HEqBy HLeFn (Tagged x v :: Type) (Tagged y w :: Type) b Source # | |
Defined in Data.HList.HSort | |
HEqBy f y x b => HEqBy (HDown f :: Type) (x :: k2) (y :: k2) b Source # | |
Defined in Data.HList.HSort | |
(HEqBy le y x b1, HNot b1 ~ b2) => HEqBy (HNeq le :: Type) (x :: k2) (y :: k2) b2 Source # | |
Defined in Data.HList.HSort |
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.
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.
Instances
HEq (x :: k) (x :: k) 'True Source # | |
Defined in Data.HList.TypeEqO | |
'False ~ b => HEq (x :: k) (y :: k) b Source # | |
Defined in Data.HList.TypeEqO |
HJust x |
Instances
(Apply p s, HUnfoldFD p (ApplyR p s) z) => HUnfoldFD p (HJust (e, s)) (e ': z) Source # | |
Show x => Show (HJust x) Source # | |
hJustA ~ HJust a => ApplyAB (HJust t) a hJustA Source # |
|
Defined in Data.HList.FakePrelude | |
FromHJust l => FromHJust (HJust e ': l) Source # | |
Defined in Data.HList.HList type FromHJustR (HJust e ': l) :: [Type] Source # | |
type HUnfoldR p (HJust (e, s)) Source # | |
Defined in Data.HList.HList | |
type FromHJustR (HJust e ': l) Source # | |
Defined in Data.HList.HList |
Instances
Show HNothing Source # | |
HUnfoldFD p HNothing ('[] :: [Type]) Source # | |
FromHJust l => FromHJust (HNothing ': l) Source # | |
Defined in Data.HList.HList type FromHJustR (HNothing ': l) :: [Type] Source # | |
type HUnfoldR p HNothing Source # | |
Defined in Data.HList.HList | |
type FromHJustR (HNothing ': l) Source # | |
Defined in Data.HList.HList |
type family HDiv2 (x :: HNat) :: HNat Source #
HDiv2 x
behaves like x
div
2
type family HLt (x :: HNat) (y :: HNat) :: Bool Source #
Less than
type family HNatEq (t1 :: HNat) (t2 :: HNat) :: Bool Source #
Equality on natural numbers (eventually to be subsumed by the universal polykinded HEq)
Instances
class HNats2Integrals (ns :: [HNat]) where Source #
hNats2Integrals :: Integral i => Proxy ns -> [i] Source #
Instances
HNats2Integrals ('[] :: [HNat]) Source # | |
Defined in Data.HList.FakePrelude hNats2Integrals :: Integral i => Proxy '[] -> [i] Source # | |
(HNats2Integrals ns, HNat2Integral n) => HNats2Integrals (n ': ns) Source # | |
Defined in Data.HList.FakePrelude hNats2Integrals :: Integral i => Proxy (n ': ns) -> [i] Source # |
class HNat2Integral (n :: HNat) where Source #
hNat2Integral :: Integral i => Proxy n -> i Source #
Instances
KnownNat (HNat2Nat n) => HNat2Integral n Source # | |
Defined in Data.HList.FakePrelude hNat2Integral :: Integral i => Proxy n -> i Source # |
The data type to be lifted to the type level
Instances
type family HBoolEQ (t1 :: Bool) (t2 :: Bool) :: Bool Source #
class HNotFD (b :: Bool) (nb :: Bool) | b -> nb, nb -> b Source #
as compared with HNot
this version is injective
class ShowLabel l where Source #
Instances
A special Proxy
for record labels, polykinded
Instances
HEqBy HLeFn x y b => HEqBy HLeFn (Label x :: Type) (Label y :: Type) b Source # | |
Defined in Data.HList.HSort | |
Label t ~ Label t' => SameLabels (Label t :: Type) (t' :: Symbol) Source # | |
Defined in Data.HList.FakePrelude | |
Label t ~ Label t' => SameLabels (Label t :: Type) (Label t' :: Type) Source # | |
Defined in Data.HList.FakePrelude | |
Label t ~ Label (Lbl ix ns n) => SameLabels (Label t :: Type) (Lbl ix ns n :: Type) Source # | |
Defined in Data.HList.Label3 | |
Label t ~ Label t' => SameLabels (Label t :: Type) (Tagged t' a :: Type) Source # | |
Defined in Data.HList.FakePrelude | |
(HasField l (Record r) u, HasFieldPath needJust ls u v) => HasFieldPath needJust (Label l ': ls) (Record r) v Source # | |
Defined in Data.HList.Dredge | |
(HasField l (Variant r) (Maybe u), HasFieldPath 'True ls u (Maybe v)) => HasFieldPath needJust (Label l ': ls) (Variant r) (Maybe v) Source # | |
Defined in Data.HList.Dredge | |
(lv ~ Tagged l v, HUnzip (Proxy :: [Type] -> Type) ls vs lvs) => HUnzip (Proxy :: [Type] -> Type) (Label l ': ls) (v ': vs) (lv ': lvs) Source # | |
Show desc => Show (Label (Lbl x ns desc)) Source # | |
IsKeyFN (Label s -> a -> b) 'True Source # | labels that impose no restriction on the type of the (single) argument which follows
|
Defined in Data.HList.Keyword | |
HExtend (Label y) (Proxy (x ': xs)) Source # | |
HExtend (Label y) (Proxy (x ': xs)) Source # | |
HExtend (Label y) (Proxy (x ': xs)) Source # | |
HExtend (Label y) (Proxy (x ': xs)) Source # | |
HExtend (Label y) (Proxy (x ': xs)) Source # |
|
HExtend (Label y) (Proxy (x ': xs)) Source # | Mixing two label kinds means we have to include
|
HExtend (Label (Lbl n ns desc)) (Proxy (x ': xs)) Source # | Mixing two label kinds means we have to include
|
HExtend (Label (Lbl n ns desc)) (Proxy (Lbl n' ns' desc' ': xs)) Source # | If possible, Label is left off:
|
HExtend (Label x) (Proxy ('[] :: [Type])) Source # | to keep types shorter, ghc-7.6 does not accept |
EnsureLabel (Label x) (Label x) Source # | |
EnsureLabel (Proxy x) (Label x) Source # | |
ToSym (a b c) x => EnsureLabel (a b c) (Label x) Source # | get the Label out of a |
Defined in Data.HList.Labelable | |
(Labelable x r s t a b, j ~ p a (f b), k2 ~ p (r s) (f (r t)), ty ~ LabelableTy r, LabeledOpticP ty p, LabeledOpticF ty f, LabeledOpticTo ty x (->), LabelablePath xs i j) => LabelablePath (Label x ': xs) i k2 Source # | |
Defined in Data.HList.Dredge hLens'Path :: Label (Label x ': xs) -> i -> k2 Source # | |
type UnLabel (proxy :: a) (Label x ': xs) Source # | |
Defined in Data.HList.Record | |
type ZipTagged (Label t ': ts :: [Type]) (v ': vs) Source # | |
type HExtendR (Label y) (Proxy (x ': xs)) Source # | |
Defined in Data.HList.Label6 | |
type HExtendR (Label y) (Proxy (x ': xs)) Source # | |
type HExtendR (Label y) (Proxy (x ': xs)) Source # | |
type HExtendR (Label y) (Proxy (x ': xs)) Source # | |
type HExtendR (Label y) (Proxy (x ': xs)) Source # | |
Defined in Data.HList.Label6 | |
type HExtendR (Label y) (Proxy (x ': xs)) Source # | |
type HExtendR (Label (Lbl n ns desc)) (Proxy (x ': xs)) Source # | |
type HExtendR (Label (Lbl n ns desc)) (Proxy (Lbl n' ns' desc' ': xs)) Source # | |
type HExtendR (Label x) (Proxy ('[] :: [Type])) Source # | |
type LabelsOf (Label l ': r) Source # | |
Defined in Data.HList.Record |
LiftA2 f |
HFmap f |
((a,b) -> f a >> b)
HSeq x |
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
Compose two instances of ApplyAB
>>>
applyAB (HComp HRead HShow) (5::Double) :: Double
5.0
HComp g f | g . f |
show
read
>>>
applyAB HRead "5.0" :: Double
5.0
print. An alternative implementation could be:
>>>
let hPrint = Fun print :: Fun Show (IO ())
This produces:
>>>
:t applyAB hPrint
applyAB hPrint :: Show a => a -> IO ()
type family FunCxt (cxts :: k) a :: Constraint Source #
Instances
type FunCxt (cxt :: ()) a Source # | should there be so many ways to write no constraint? |
Defined in Data.HList.FakePrelude type FunCxt (cxt :: ()) a = () | |
type FunCxt (cxt :: Type) a Source # | |
Defined in Data.HList.FakePrelude | |
type FunCxt ('[] :: [k]) a Source # | |
Defined in Data.HList.FakePrelude type FunCxt ('[] :: [k]) a = () | |
type FunCxt (x ': xs :: [Type -> Constraint]) a Source # | |
Defined in Data.HList.FakePrelude | |
type FunCxt (cxt :: Type -> Constraint) a Source # | |
Defined in Data.HList.FakePrelude |
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
,
class ApplyAB f a b where Source #
No constraints on result and argument types
Instances
(y ~ y', fg ~ (x -> y, y' -> z), r ~ (x -> z)) => ApplyAB Comp fg r Source # | |
Defined in Data.HList.FakePrelude | |
(f1 ~ (a -> b -> c), f2 ~ (b -> a -> c)) => ApplyAB HFlip f1 f2 Source # | |
Defined in Data.HList.FakePrelude | |
(io ~ IO (), Show x) => ApplyAB HPrint x io Source # | |
Defined in Data.HList.FakePrelude | |
(String ~ string, Read a) => ApplyAB HRead string a Source # | |
Defined in Data.HList.FakePrelude | |
(String ~ string, Show a) => ApplyAB HShow a string Source # | |
Defined in Data.HList.FakePrelude | |
Tagged t x ~ tx => ApplyAB HUntag tx x Source # | |
Defined in Data.HList.FakePrelude | |
(x ~ Proxy y, Monoid y) => ApplyAB ConstMempty x y Source # | |
Defined in Data.HList.HList applyAB :: ConstMempty -> x -> y Source # | |
(x ~ (e, HList l), y ~ HList (e ': l)) => ApplyAB FHCons x y Source # | |
Defined in Data.HList.HList | |
hJustA ~ HJust a => ApplyAB HFromJust hJustA a Source # | |
Defined in Data.HList.HList | |
(aa ~ (a, a), Monoid a) => ApplyAB UncurryMappend aa a Source # | |
Defined in Data.HList.HList applyAB :: UncurryMappend -> aa -> a Source # | |
(aa ~ (a, a), Semigroup a) => ApplyAB UncurrySappend aa a Source # | |
Defined in Data.HList.HList applyAB :: UncurrySappend -> aa -> a Source # | |
(HZip3 a b c, x ~ (HList a, HList b), y ~ HList c) => ApplyAB HZipF x y Source # | |
Defined in Data.HList.HZip | |
(x ~ Tagged l v, y ~ HList '[Label l, v]) => ApplyAB TaggedToKW x y Source # | |
Defined in Data.HList.Keyword applyAB :: TaggedToKW -> x -> y Source # | |
tx ~ Tagged t x => ApplyAB TaggedFn x tx Source # | |
Defined in Data.HList.Record | |
(ux ~ RecordU x, hx ~ HList x, RecordUToRecord x) => ApplyAB BoxF ux hx Source # | |
Defined in Data.HList.RecordU | |
(hx ~ HList x, ux ~ RecordU x, RecordToRecordU x) => ApplyAB UnboxF hx ux Source # | |
Defined in Data.HList.RecordU | |
y ~ Tagged t (Maybe e) => ApplyAB ConstTaggedNothing x y Source # | |
Defined in Data.HList.Variant applyAB :: ConstTaggedNothing -> x -> y Source # | |
(mx ~ Maybe x, my ~ Maybe y, HCast y x) => ApplyAB HCastF mx my Source # | |
Defined in Data.HList.Variant | |
(x ~ (Tagged t (Maybe e), [Variant v]), y ~ [Variant (Tagged t e ': v)], MkVariant t e (Tagged t e ': v)) => ApplyAB HMaybiedToVariantFs x y Source # | |
Defined in Data.HList.Variant applyAB :: HMaybiedToVariantFs -> x -> y Source # | |
(ee ~ (e, e), Eq e, bool ~ Bool) => ApplyAB UncurryEq ee bool Source # | |
Defined in Data.HList.Variant | |
e' ~ e => ApplyAB HRmTag (e, t) e' Source # | |
Defined in Data.HList.HList | |
(y ~ ReadP x, Read x) => ApplyAB ReadElement (Proxy x) y Source # | |
Defined in Data.HList.HList applyAB :: ReadElement -> Proxy x -> y Source # | |
(Read v, ShowLabel l, x ~ Tagged l v, ReadP x ~ y) => ApplyAB ReadComponent (Proxy x) y Source # | |
Defined in Data.HList.Record applyAB :: ReadComponent -> Proxy x -> y Source # | |
(Data d, (c (d -> b), d) ~ x, c b ~ y) => ApplyAB (GfoldlK c) x y Source # | |
Defined in Data.HList.Data | |
(Data b, x ~ (t, c (b -> r)), y ~ c r) => ApplyAB (GunfoldK c) x y Source # | |
Defined in Data.HList.Data | |
(x ~ t a, y ~ t b, Functor t, ApplyAB f a b) => ApplyAB (HFmap f) x y Source # | |
Defined in Data.HList.FakePrelude | |
hJustA ~ HJust a => ApplyAB (HJust t) a hJustA Source # |
|
Defined in Data.HList.FakePrelude | |
(Monad m, ApplyAB f x fx, fx ~ m (), pair ~ (x, m ()), ApplyAB f x (m ())) => ApplyAB (HSeq f) pair fx Source # | |
Defined in Data.HList.FakePrelude | |
(ApplyAB f (x, y) z, mz ~ m z, mxy ~ (m x, m y), Applicative m) => ApplyAB (LiftA2 f) mxy mz Source # | |
Defined in Data.HList.FakePrelude | |
(hxs ~ HList xs, hxxs ~ HList (x ': xs)) => ApplyAB (FHCons2 x) hxs hxxs Source # | |
Defined in Data.HList.HList | |
et ~ (e, t) => ApplyAB (HAddTag t) e et Source # | |
Defined in Data.HList.HList | |
(HMapCxt r f a b, as ~ r a, bs ~ r b) => ApplyAB (HMap f) as bs Source # | |
Defined in Data.HList.HList | |
(HMapCxt HList f a b, as ~ HList a, bs ~ HList b) => ApplyAB (HMapL f) as bs Source # | |
Defined in Data.HList.HList | |
(l ~ [e'], ApplyAB f e e', el ~ (e, l)) => ApplyAB (Mapcar f) el l Source # | |
Defined in Data.HList.HList | |
(HMapCxt Record f x y, rx ~ Record x, ry ~ Record y) => ApplyAB (HMapR f) rx ry Source # | |
Defined in Data.HList.Record | |
(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. |
Defined in Data.HList.Variant | |
ApplyAB f e e' => ApplyAB (MapCar f) (e, HList l) (HList (e' ': l)) Source # | |
(ApplyAB f a b, ApplyAB g b c) => ApplyAB (HComp g f) a c Source # | |
Defined in Data.HList.FakePrelude | |
(x' ~ x, y' ~ y) => ApplyAB (x' -> y') x y Source # | note this function will only be available at a single type
(that is, |
Defined in Data.HList.FakePrelude | |
(FunCxt cxt a, FunApp getb a ~ b) => ApplyAB (Fun cxt getb) a b Source # | |
Defined in Data.HList.FakePrelude | |
(FunCxt cxt b, FunApp geta b ~ a) => ApplyAB (Fun' cxt geta) a b Source # | |
Defined in Data.HList.FakePrelude |
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
.
Instances
HLookupByHNat n l => Apply (FHLookupByHNat l) (Proxy n) Source # | |
Defined in Data.HList.HArray type ApplyR (FHLookupByHNat l) (Proxy n) Source # apply :: FHLookupByHNat l -> Proxy n -> ApplyR (FHLookupByHNat l) (Proxy n) Source # | |
(ch ~ Proxy (HBoolEQ sel (KMember n ns)), Apply (ch, FHUProj sel ns) (HList (e ': l), Proxy n)) => Apply (FHUProj sel ns) (HList (e ': l), Proxy n) Source # | |
Apply (FHUProj sel ns) (HList ('[] :: [Type]), n) Source # | |
Apply (FHUProj sel ns) (HList l, Proxy ('HSucc n)) => Apply (Proxy 'False, FHUProj sel ns) (HList (e ': l), Proxy n) Source # | |
Apply (Proxy 'True, FHUProj sel ns) (HList (e ': l), Proxy n) Source # | |
labelToProxy :: Label l -> Proxy l Source #
asLengthOf :: SameLength x y => r x -> s y -> r x 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
re-exports
module Data.Proxy
module Data.Tagged
class Semigroup a => Monoid a where #
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following:
- Right identity
x
<>
mempty
= x- Left identity
mempty
<>
x = x- Associativity
x
(<>
(y<>
z) = (x<>
y)<>
zSemigroup
law)- Concatenation
mconcat
=foldr
(<>
)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 newtype
s and make those instances
of Monoid
, e.g. Sum
and Product
.
NOTE: Semigroup
is a superclass of Monoid
since base-4.11.0.0.
Identity of mappend
>>>
"Hello world" <> mempty
"Hello world"
An associative operation
NOTE: This method is redundant and has the default
implementation
since base-4.11.0.0.
Should it be implemented manually, since mappend
= (<>
)mappend
is a synonym for
(<>
), it is expected that the two functions are defined the same
way. In a future GHC release mappend
will be removed from Monoid
.
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.
>>>
mconcat ["Hello", " ", "Haskell", "!"]
"Hello Haskell!"
Instances
Monoid All | Since: base-2.1 |
Monoid Any | Since: base-2.1 |
Monoid Ordering | Since: base-2.1 |
Monoid Doc | |
Monoid () | Since: base-2.1 |
(HProxies a, HMapCxt HList ConstMempty (AddProxy a) a, HZip HList a a aa, HMapCxt HList UncurryMappend aa a) => Monoid (HList a) Source # | Analogous to the Monoid instance for tuples
|
Monoid (HList r) => Monoid (Record r) Source # | |
Monoid (Variant l) => Monoid (TIC l) Source # | |
Monoid (HList a) => Monoid (TIP a) Source # | |
(Monoid x, Monoid (Variant (a ': b))) => Monoid (Variant (Tagged t x ': (a ': b))) Source # | |
(Unvariant '[Tagged t x] x, Monoid x) => Monoid (Variant '[Tagged t x]) Source # | |
Monoid (Comparison a) |
mempty :: Comparison a mempty = Comparison _ _ -> EQ |
Defined in Data.Functor.Contravariant mempty :: Comparison a # mappend :: Comparison a -> Comparison a -> Comparison a # mconcat :: [Comparison a] -> Comparison a # | |
Monoid (Equivalence a) |
mempty :: Equivalence a mempty = Equivalence _ _ -> True |
Defined in Data.Functor.Contravariant mempty :: Equivalence a # mappend :: Equivalence a -> Equivalence a -> Equivalence a # mconcat :: [Equivalence a] -> Equivalence a # | |
Monoid (Predicate a) |
mempty :: Predicate a mempty = _ -> True |
Monoid a => Monoid (Identity a) | Since: base-4.9.0.0 |
Monoid (First a) | Since: base-2.1 |
Monoid (Last a) | Since: base-2.1 |
Monoid a => Monoid (Down a) | Since: base-4.11.0.0 |
(Ord a, Bounded a) => Monoid (Max a) | Since: base-4.9.0.0 |
(Ord a, Bounded a) => Monoid (Min a) | Since: base-4.9.0.0 |
Monoid m => Monoid (WrappedMonoid m) | Since: base-4.9.0.0 |
Defined in Data.Semigroup mempty :: WrappedMonoid m # mappend :: WrappedMonoid m -> WrappedMonoid m -> WrappedMonoid m # mconcat :: [WrappedMonoid m] -> WrappedMonoid m # | |
Monoid a => Monoid (Dual a) | Since: base-2.1 |
Monoid (Endo a) | Since: base-2.1 |
Num a => Monoid (Product a) | Since: base-2.1 |
Num a => Monoid (Sum a) | Since: base-2.1 |
Monoid p => Monoid (Par1 p) | Since: base-4.12.0.0 |
Monoid (Seq a) | |
Monoid a => Monoid (IO a) | Since: base-4.9.0.0 |
Monoid (Doc a) | |
Monoid a => Monoid (Q a) | Since: template-haskell-2.17.0.0 |
Semigroup a => Monoid (Maybe a) | Lift a semigroup into Since 4.11.0: constraint on inner Since: base-2.1 |
Monoid a => Monoid (a) | Since: base-4.15 |
Monoid [a] | Since: base-2.1 |
Monoid a => Monoid (Op a b) |
mempty :: Op a b mempty = Op _ -> mempty |
Monoid (Proxy s) | Since: base-4.7.0.0 |
Monoid (U1 p) | Since: base-4.12.0.0 |
Monoid a => Monoid (ST s a) | Since: base-4.11.0.0 |
Monoid b => Monoid (a -> b) | Since: base-2.1 |
(Monoid a, Monoid b) => Monoid (a, b) | Since: base-2.1 |
Monoid a => Monoid (Const a b) | Since: base-4.9.0.0 |
(Applicative f, Monoid a) => Monoid (Ap f a) | Since: base-4.12.0.0 |
Alternative f => Monoid (Alt f a) | Since: base-4.8.0.0 |
Monoid (f p) => Monoid (Rec1 f p) | Since: base-4.12.0.0 |
(Profunctor p, Arrow p, Semigroup b, Monoid b) => Monoid (Closure p a b) | |
ArrowPlus p => Monoid (Tambara p a b) | |
(Semigroup a, Monoid a) => Monoid (Tagged s a) | |
(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c) | Since: base-2.1 |
(Monoid (f a), Monoid (g a)) => Monoid (Product f g a) | Since: base-4.16.0.0 |
(Monoid (f p), Monoid (g p)) => Monoid ((f :*: g) p) | Since: base-4.12.0.0 |
Monoid c => Monoid (K1 i c p) | Since: base-4.12.0.0 |
Monoid r => Monoid (Forget r a b) | Via Since: profunctors-5.6.2 |
(Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d) | Since: base-2.1 |
Monoid (f (g a)) => Monoid (Compose f g a) | Since: base-4.16.0.0 |
Monoid (f (g p)) => Monoid ((f :.: g) p) | Since: base-4.12.0.0 |
Monoid (f p) => Monoid (M1 i c f p) | Since: base-4.12.0.0 |
(Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e) | Since: base-2.1 |