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 {
- getField :: h (AssocValue kv)
- (@=) :: 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 (Field h) xs (k :> v), Associate k v xs, Labelling k p, Wrapper h) => Optic' p f (t (Field h) xs) (Repr h v)
- type FieldName k = Optic' (LabelPhantom k) Proxy (Inextensible (Field Proxy) '[k :> ()]) ()
- liftField :: (g (AssocValue kv) -> h (AssocValue kv)) -> Field g kv -> Field h kv
- liftField2 :: (f (AssocValue kv) -> g (AssocValue kv) -> h (AssocValue kv)) -> Field f kv -> Field g kv -> Field h kv
- type RecordOf h = (:*) (Field h)
- type Record = RecordOf Identity
- emptyRecord :: Record '[]
- type VariantOf h = (:|) (Field h)
- type Variant = VariantOf Identity
- 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 AssocKey (kv :: Assoc k v) :: k where ...
- type family AssocValue (kv :: Assoc k v) :: v where ...
- class (pk (AssocKey kv), pv (AssocValue kv)) => KeyValue pk pv kv
- proxyAssocKey :: proxy kv -> Proxy (AssocKey kv)
- proxyAssocValue :: proxy kv -> Proxy (AssocValue kv)
- stringAssocKey :: (IsString a, KnownSymbol (AssocKey kv)) => proxy kv -> a
- class pk (AssocKey kv) => KeyIs pk kv
- class pv (AssocValue kv) => ValueIs pv kv
- data LabelPhantom s a b
- type family Labelling s p :: Constraint where ...
- data Inextensible (h :: k -> Type) (xs :: [k])
Documentation
newtype Field (h :: v -> Type) (kv :: Assoc k v) Source #
Field | |
|
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 (Field h) xs (k :> v), Associate k v xs, Labelling k p, Wrapper h) => Optic' p f (t (Field h) xs) (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 (Field Proxy) '[k :> ()]) () 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 (AssocValue kv) -> h (AssocValue kv)) -> Field g kv -> Field h kv Source #
Lift a function for the content.
liftField2 :: (f (AssocValue kv) -> g (AssocValue kv) -> h (AssocValue kv)) -> Field f kv -> Field g kv -> Field h kv Source #
Lift a function for the content.
Records and variants
type RecordOf h = (:*) (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 = (:|) (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
type family AssocValue (kv :: Assoc k v) :: v where ... Source #
Take the type of the value
AssocValue (k :> v) = v |
class (pk (AssocKey kv), pv (AssocValue kv)) => KeyValue pk pv kv Source #
Combined constraint for Assoc
Instances
(pk k2, pv v2) => KeyValue (pk :: k1 -> Constraint) (pv :: v1 -> Constraint) (k2 :> v2 :: Assoc k1 v1) Source # | |
Defined in Data.Extensible.Field |
proxyAssocKey :: proxy kv -> Proxy (AssocKey kv) Source #
proxyAssocValue :: proxy kv -> Proxy (AssocValue kv) Source #
Proxy-level AssocValue
.
stringAssocKey :: (IsString a, KnownSymbol (AssocKey kv)) => proxy kv -> a Source #
class pk (AssocKey kv) => KeyIs pk kv Source #
Constraint applied to AssocKey
Instances
pk k2 => KeyIs (pk :: k1 -> Constraint) (k2 :> v2 :: Assoc k1 v1) Source # | |
Defined in Data.Extensible.Field |
class pv (AssocValue kv) => ValueIs pv kv Source #
Constraint applied to AssocValue
Instances
pv v2 => ValueIs (pv :: v1 -> Constraint) (k2 :> v2 :: Assoc k1 v1) Source # | |
Defined in Data.Extensible.Field |
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 (h :: k -> Type) (xs :: [k]) Source #
The trivial inextensible data type
Instances
(Functor f, Profunctor p) => Extensible f p (Inextensible :: (k -> Type) -> [k] -> Type) Source # | |
Defined in Data.Extensible.Field type ExtensibleConstr Inextensible h xs x :: Constraint Source # pieceAt :: ExtensibleConstr Inextensible h xs x => Membership xs x -> Optic' p f (Inextensible h xs) (h x) Source # | |
type ExtensibleConstr (Inextensible :: (k -> Type) -> [k] -> Type) (h :: k -> Type) (xs :: [k]) (x :: k) Source # | |
Defined in Data.Extensible.Field type ExtensibleConstr (Inextensible :: (k -> Type) -> [k] -> Type) (h :: k -> Type) (xs :: [k]) (x :: k) = () |