Copyright | (c) Fumiaki Kinoshita 2018 |
---|---|
License | BSD3 |
Maintainer | Fumiaki Kinoshita <fumiexcel@gmail.com> |
Safe Haskell | None |
Language | Haskell2010 |
Flexible records and variants
Synopsis
- newtype Field (h :: v -> Type) (kv :: Assoc k v) = Field {}
- (@=) :: Wrapper h => FieldName k -> Repr h v -> Field h (k :> v)
- (<@=>) :: (Functor f, Wrapper h) => FieldName k -> f (Repr h v) -> Comp f (Field h) (k :> v)
- (@:>) :: FieldName k -> h v -> Field h (k :> v)
- (@==) :: FieldName (k :: Symbol) -> v -> Field Identity (k :> v)
- type FieldOptic k = forall kind. forall f p t xs (h :: kind -> Type) (v :: kind). (Extensible f p t, ExtensibleConstr t xs (Field h) (k :> v), Lookup xs k v, Labelling k p, Wrapper h) => Optic' p f (t xs (Field h)) (Repr h v)
- type FieldName k = Optic' (LabelPhantom k) Proxy (Inextensible '[k :> ()] (Field Proxy)) ()
- liftField :: (g (TargetOf kv) -> h (TargetOf kv)) -> Field g kv -> Field h kv
- liftField2 :: (f (TargetOf kv) -> g (TargetOf kv) -> h (TargetOf kv)) -> Field f kv -> Field g kv -> Field h kv
- type RecordOf h xs = xs :& Field h
- type Record xs = RecordOf Identity xs
- emptyRecord :: Record '[]
- type VariantOf h xs = xs :/ Field h
- type Variant xs = VariantOf Identity xs
- matchWithField :: (forall x. f x -> g x -> r) -> RecordOf f xs -> VariantOf g xs -> r
- matchField :: RecordOf (Match h r) xs -> VariantOf h xs -> r
- type family KeyOf (kv :: Assoc k v) :: k where ...
- proxyKeyOf :: proxy kv -> Proxy (KeyOf kv)
- stringKeyOf :: (IsString a, KnownSymbol (KeyOf kv)) => proxy kv -> a
- type family TargetOf (kv :: Assoc k v) :: v where ...
- proxyTargetOf :: proxy kv -> Proxy (TargetOf kv)
- class pk (KeyOf kv) => KeyIs (pk :: k -> Constraint) (kv :: Assoc k v)
- class pv (TargetOf kv) => TargetIs (pv :: k1 -> Constraint) (kv :: Assoc k k1)
- class (pk (KeyOf kv), pv (TargetOf kv)) => KeyTargetAre (pk :: k -> Constraint) (pv :: k1 -> Constraint) (kv :: Assoc k k1)
- type AssocKey kv = KeyOf kv
- type AssocValue kv = TargetOf kv
- type ValueIs = TargetIs
- type KeyValue = KeyTargetAre
- proxyAssocKey :: proxy kv -> Proxy (KeyOf kv)
- stringAssocKey :: (IsString a, KnownSymbol (KeyOf kv)) => proxy kv -> a
- proxyAssocValue :: proxy kv -> Proxy (TargetOf kv)
- data LabelPhantom s a b
- type family Labelling s p :: Constraint where ...
- data Inextensible (xs :: [k]) (h :: k -> Type)
Documentation
newtype Field (h :: v -> Type) (kv :: Assoc k v) Source #
Instances
(@=) :: Wrapper h => FieldName k -> Repr h v -> Field h (k :> v) infix 1 Source #
Annotate a value by the field name.
foo :: Record
'["num" >: Int, "str" >: String]
foo = #num @= 42
<: #str @= "foo"
<: nil
(<@=>) :: (Functor f, Wrapper h) => FieldName k -> f (Repr h v) -> Comp f (Field h) (k :> v) infix 1 Source #
(@:>) :: FieldName k -> h v -> Field h (k :> v) infix 1 Source #
Annotate a value by the field name without Wrapper
.
(@==) :: FieldName (k :: Symbol) -> v -> Field Identity (k :> v) infix 1 Source #
Kind-monomorphic, unwrapped version of @=
type FieldOptic k = forall kind. forall f p t xs (h :: kind -> Type) (v :: kind). (Extensible f p t, ExtensibleConstr t xs (Field h) (k :> v), Lookup xs k v, Labelling k p, Wrapper h) => Optic' p f (t xs (Field h)) (Repr h v) Source #
FieldOptic s
is a type of optics that points a field/constructor named s
.
The yielding fields can be
Lenses
for Record
s and
Prisms
for Variant
s.
FieldOptic
"foo" = Associate "foo" a xs => Lens' (Record
xs) aFieldOptic
"foo" = Associate "foo" a xs => Prism' (Variant
xs) a
FieldOptic
s can be generated using mkField
defined in the Data.Extensible.TH module.
type FieldName k = Optic' (LabelPhantom k) Proxy (Inextensible '[k :> ()] (Field Proxy)) () Source #
When you see this type as an argument, it expects a FieldLens
.
This type is used to resolve the name of the field internally.
liftField :: (g (TargetOf kv) -> h (TargetOf kv)) -> Field g kv -> Field h kv Source #
Lift a function for the content.
liftField2 :: (f (TargetOf kv) -> g (TargetOf kv) -> h (TargetOf kv)) -> Field f kv -> Field g kv -> Field h kv Source #
Lift a function for the content.
Records and variants
type RecordOf h xs = xs :& Field h Source #
The type of records which contain several fields.
RecordOf :: (v -> *) -> [Assoc k v] -> *
emptyRecord :: Record '[] Source #
An empty Record
.
type VariantOf h xs = xs :/ Field h Source #
The dual of RecordOf
VariantOf :: (v -> *) -> [Assoc k v] -> *
Matching
matchWithField :: (forall x. f x -> g x -> r) -> RecordOf f xs -> VariantOf g xs -> r Source #
Select a corresponding field of a variant.
Key / value
stringKeyOf :: (IsString a, KnownSymbol (KeyOf kv)) => proxy kv -> a #
proxyTargetOf :: proxy kv -> Proxy (TargetOf kv) #
Proxy-level TargetOf
.
class pk (KeyOf kv) => KeyIs (pk :: k -> Constraint) (kv :: Assoc k v) #
Constraint applied to KeyOf
Instances
pk k2 => KeyIs (pk :: k1 -> Constraint) (k2 :> v2 :: Assoc k1 v1) | |
Defined in Type.Membership |
class pv (TargetOf kv) => TargetIs (pv :: k1 -> Constraint) (kv :: Assoc k k1) #
Constraint applied to TargetOf
Instances
pv v2 => TargetIs (pv :: v1 -> Constraint) (k2 :> v2 :: Assoc k1 v1) | |
Defined in Type.Membership |
class (pk (KeyOf kv), pv (TargetOf kv)) => KeyTargetAre (pk :: k -> Constraint) (pv :: k1 -> Constraint) (kv :: Assoc k k1) #
Combined constraint for Assoc
Instances
(pk k2, pv v2) => KeyTargetAre (pk :: k1 -> Constraint) (pv :: v1 -> Constraint) (k2 :> v2 :: Assoc k1 v1) | |
Defined in Type.Membership |
deprecated
type AssocValue kv = TargetOf kv Source #
Deprecated: Use TargetOf instead
type KeyValue = KeyTargetAre Source #
Deprecated: Use KeyTargetAre instead
proxyAssocKey :: proxy kv -> Proxy (KeyOf kv) Source #
Deprecated: Use proxyKeyOf instead
stringAssocKey :: (IsString a, KnownSymbol (KeyOf kv)) => proxy kv -> a Source #
Deprecated: Use stringKeyOf instead
proxyAssocValue :: proxy kv -> Proxy (TargetOf kv) Source #
Deprecated: Use proxyTargetOf instead
Internal
data LabelPhantom s a b Source #
A ghostly type which spells the field name
Instances
Profunctor (LabelPhantom s :: Type -> Type -> Type) Source # | |
Defined in Data.Extensible.Field dimap :: (a -> b) -> (c -> d) -> LabelPhantom s b c -> LabelPhantom s a d # lmap :: (a -> b) -> LabelPhantom s b c -> LabelPhantom s a c # rmap :: (b -> c) -> LabelPhantom s a b -> LabelPhantom s a c # (#.) :: Coercible c b => q b c -> LabelPhantom s a b -> LabelPhantom s a c # (.#) :: Coercible b a => LabelPhantom s b c -> q a b -> LabelPhantom s a c # |
type family Labelling s p :: Constraint where ... Source #
Signifies a field name internally
Labelling s (LabelPhantom t) = s ~ t | |
Labelling s p = () |
data Inextensible (xs :: [k]) (h :: k -> Type) Source #
The trivial inextensible data type
Instances
(Functor f, Profunctor p) => Extensible f p (Inextensible :: [k] -> (k -> Type) -> Type) Source # | |
Defined in Data.Extensible.Field type ExtensibleConstr Inextensible xs h x :: Constraint Source # pieceAt :: ExtensibleConstr Inextensible xs h x => Membership xs x -> Optic' p f (Inextensible xs h) (h x) Source # | |
type ExtensibleConstr (Inextensible :: [k] -> (k -> Type) -> Type) (xs :: [k]) (h :: k -> Type) (x :: k) Source # | |
Defined in Data.Extensible.Field type ExtensibleConstr (Inextensible :: [k] -> (k -> Type) -> Type) (xs :: [k]) (h :: k -> Type) (x :: k) = () |