Copyright | (c) Fumiaki Kinoshita 2018 |
---|---|
License | BSD3 |
Maintainer | Fumiaki Kinoshita <fumiexcel@gmail.com> |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Flexible records and variants
Synopsis
- newtype Field (h :: v -> Type) (kv :: Assoc k v) = Field {}
- (@=) :: Wrapper h => Proxy k -> Repr h v -> Field h (k ':> v)
- (<@=>) :: (Functor f, Wrapper h) => Proxy k -> f (Repr h v) -> Compose f (Field h) (k ':> v)
- (@:>) :: Proxy k -> h v -> Field h (k ':> v)
- (@==) :: Proxy (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, Wrapper h) => Optic' p f (t xs (Field h)) (Repr h v)
- xlb :: Proxy k -> FieldOptic k
- 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 :: forall {k} {v} proxy (kv :: Assoc k v). proxy kv -> Proxy (KeyOf kv)
- stringKeyOf :: forall {v} a (kv :: Assoc Symbol v) proxy. (IsString a, KnownSymbol (KeyOf kv)) => proxy kv -> a
- type family TargetOf (kv :: Assoc k v) :: v where ...
- proxyTargetOf :: forall {k1} {k2} proxy (kv :: Assoc k1 k2). proxy kv -> Proxy (TargetOf kv)
- class pk (KeyOf kv) => KeyIs (pk :: k -> Constraint) (kv :: Assoc k v)
- class pv (TargetOf kv) => TargetIs (pv :: k -> Constraint) (kv :: Assoc k1 k)
- class (pk (KeyOf kv), pv (TargetOf kv)) => KeyTargetAre (pk :: k -> Constraint) (pv :: k1 -> Constraint) (kv :: Assoc k k1)
Documentation
newtype Field (h :: v -> Type) (kv :: Assoc k v) Source #
A
is Field
h (k ':> v)h v
annotated with the field name k
.
Field
:: (v -> Type) -> Assoc k v -> Type
Instances
(@=) :: Wrapper h => Proxy 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) => Proxy k -> f (Repr h v) -> Compose f (Field h) (k ':> v) infix 1 Source #
(@:>) :: Proxy k -> h v -> Field h (k ':> v) infix 1 Source #
Annotate a value by the field name without Wrapper
.
(@==) :: Proxy (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, 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" = Lookup xs "foo" a => Lens' (Record
xs) aFieldOptic
"foo" = Lookup xs "foo" a => Prism' (Variant
xs) a
FieldOptic
s can be generated using mkField
defined in the Data.Extensible.TH module.
xlb :: Proxy k -> FieldOptic k Source #
Specialised version of itemAssoc
. Stands for "eXtensible LaBel"
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 -> Type) -> [Assoc k v] -> Type
emptyRecord :: Record '[] Source #
An empty Record
.
type VariantOf h xs = xs :/ Field h Source #
The dual of RecordOf
VariantOf :: (v -> Type) -> [Assoc k v] -> Type
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
proxyKeyOf :: forall {k} {v} proxy (kv :: Assoc k v). proxy kv -> Proxy (KeyOf kv) #
stringKeyOf :: forall {v} a (kv :: Assoc Symbol v) proxy. (IsString a, KnownSymbol (KeyOf kv)) => proxy kv -> a #
proxyTargetOf :: forall {k1} {k2} proxy (kv :: Assoc k1 k2). 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 :: k -> Constraint) (kv :: Assoc k1 k) #
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 |