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 {
- 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)
- type FieldOptic k = forall f p t xs h v. (Extensible f p t, 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 :> ()]`) ()
- 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 :: k
- type family AssocValue kv :: v
- class (pk (AssocKey kv), pv (AssocValue kv)) => KeyValue pk pv kv
- proxyAssocKey :: proxy kv -> Proxy (AssocKey kv)
- data LabelPhantom s a b
- type family Labelling s p :: Constraint
- data Inextensible h xs
Documentation
Field | |
|
Wrapper k h => Wrapper (Assoc k k) (Field k k h) Source | |
(KnownSymbol k1, Wrapper k h, Show (Repr k h v)) => Show (Field k Symbol h ((:>) Symbol k k v)) Source | Shows in |
Monoid (h (AssocValue k k1 kv)) => Monoid (Field k k h kv) Source | |
type Repr (Assoc k1 k) (Field k k1 h) kv = Repr k h (AssocValue k k1 kv) Source |
(@=) :: 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 (@=
)
(@:>) :: FieldName k -> h v -> Field h (k :> v) infix 1 Source
Annotate a value by the field name without Wrapper
.
type FieldOptic k = forall f p t xs h v. (Extensible f p t, 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.
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.
matchField :: RecordOf (Match h r) xs -> VariantOf h xs -> r Source
Key / value
class (pk (AssocKey kv), pv (AssocValue kv)) => KeyValue pk pv kv Source
proxyAssocKey :: proxy kv -> Proxy (AssocKey kv) Source
Internal
data LabelPhantom s a b Source
A ghostly type which spells the field name
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, Profunctor p) => Extensible k f p (Inextensible k) Source |