Copyright | (c) Fumiaki Kinoshita 2017 |
---|---|
License | BSD3 |
Maintainer | Fumiaki Kinoshita <fumiexcel@gmail.com> |
Safe Haskell | None |
Language | Haskell2010 |
Flexible records and variants
- 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 kind. 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 :> ()]) ()
- 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)
- data LabelPhantom s a b
- type family Labelling s p :: Constraint where ...
- data Inextensible h xs
Documentation
Field | |
|
Wrapper v h => Wrapper (Assoc k v) (Field k v h) Source # | |
Bounded (h (AssocValue k v kv)) => Bounded (Field k v h kv) Source # | |
Enum (h (AssocValue k v kv)) => Enum (Field k v h kv) Source # | |
Eq (h (AssocValue k v kv)) => Eq (Field k v h kv) Source # | |
Floating (h (AssocValue k v kv)) => Floating (Field k v h kv) Source # | |
Fractional (h (AssocValue k v kv)) => Fractional (Field k v h kv) Source # | |
Integral (h (AssocValue k v kv)) => Integral (Field k v h kv) Source # | |
Num (h (AssocValue k v kv)) => Num (Field k v h kv) Source # | |
Ord (h (AssocValue k v kv)) => Ord (Field k v h kv) Source # | |
Real (h (AssocValue k v kv)) => Real (Field k v h kv) Source # | |
RealFloat (h (AssocValue k v kv)) => RealFloat (Field k v h kv) Source # | |
RealFrac (h (AssocValue k v kv)) => RealFrac (Field k v h kv) Source # | |
(KnownSymbol k, Wrapper v h, Show (Repr v h v1)) => Show (Field Symbol v h ((:>) Symbol v k v1)) Source # | Shows in |
Semigroup (h (AssocValue k v kv)) => Semigroup (Field k v h kv) Source # | |
Monoid (h (AssocValue k v kv)) => Monoid (Field k v h kv) Source # | |
Storable (h (AssocValue k v kv)) => Storable (Field k v h kv) Source # | |
NFData (h (AssocValue k v kv)) => NFData (Field k v h kv) Source # | |
type Repr (Assoc k v) (Field k v h) 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 kind. 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.
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
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 where ... Source #
Signifies a field name internally
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 # | |