Copyright | (c) Fumiaki Kinoshita 2015 |
---|---|
License | BSD3 |
Maintainer | Fumiaki Kinoshita <fumiexcel@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | Safe |
Language | Haskell2010 |
Flexible records and variants Example: https://github.com/fumieval/extensible/blob/master/examples/records.hs
- newtype Field h kv = Field (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)
- type FieldOptic k = forall f p t xs h v. (Extensible f p t, Associate k v xs, Labelling k p, Wrapper h) => p (Repr h v) (f (Repr h v)) -> p (t (Field h) xs) (f (t (Field h) xs))
- type FieldName k = forall v. LabelPhantom k () (Proxy ()) -> LabelPhantom k (Inextensible (Field Proxy) `[k :> v]`) (Proxy (Inextensible (Field Proxy) `[k :> v]`))
- type RecordOf h = (:*) (Field h)
- type Record = RecordOf Identity
- emptyRecord :: Record []
- type VariantOf h = (:|) (Field h)
- type Variant = VariantOf Identity
- type family AssocKey kv :: k
- type family AssocValue kv :: v
- class (pk (AssocKey kv), pv (AssocValue kv)) => KeyValue pk pv kv
- data LabelPhantom s a b
- type family Labelling s p :: Constraint
- data Inextensible h xs
Documentation
Field (h (AssocValue kv)) |
(@=) :: Wrapper h => FieldName k -> Repr h v -> Field h (k :> v) infix 1 Source
Annotate a value by the field name.
(<@=>) :: (Functor f, Wrapper h) => FieldName k -> f (Repr h v) -> Comp f (Field h) (k :> v) infix 1 Source
Lifted (@=
)
type FieldOptic k = forall f p t xs h v. (Extensible f p t, Associate k v xs, Labelling k p, Wrapper h) => p (Repr h v) (f (Repr h v)) -> p (t (Field h) xs) (f (t (Field h) xs)) 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 = forall v. LabelPhantom k () (Proxy ()) -> LabelPhantom k (Inextensible (Field Proxy) `[k :> v]`) (Proxy (Inextensible (Field Proxy) `[k :> v]`)) 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.
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] -> *
Constraint
type family AssocValue kv :: v Source
AssocValue (k :> v) = v |
class (pk (AssocKey kv), pv (AssocValue kv)) => KeyValue pk pv kv Source
Internal
data LabelPhantom s a b Source
A ghostly type which spells the field name
Functor f => Extensible k f (LabelPhantom k * * s) (Inextensible k) Source | |
Profunctor (LabelPhantom k * * s) Source |
type family Labelling s p :: Constraint Source
Labelling s (LabelPhantom t) = s ~ t | |
Labelling s p = () |
data Inextensible h xs Source
The trivial inextensible data type
Functor f => Extensible k f (LabelPhantom k * * s) (Inextensible k) Source |