Copyright | (c) Fumiaki Kinoshita 2015 |
---|---|
License | BSD3 |
Maintainer | Fumiaki Kinoshita <fumiexcel@gmail.com> |
Stability | experimental |
Portability | non-portable |
Safe Haskell | None |
Language | Haskell2010 |
Flexible records and variants Example: https://github.com/fumieval/extensible/blob/master/examples/records.hs
- module Data.Extensible.Class
- module Data.Extensible.Inclusion
- (@=) :: FieldName k -> v -> Field (k :> v)
- (<@=>) :: Functor f => FieldName k -> f v -> Comp f Field (k :> v)
- mkField :: String -> DecsQ
- data Field kv where
- getField :: Field (k :> v) -> v
- type FieldOptic k = forall f p q t xs v. (Functor f, Profunctor p, Extensible f p q t, Associate k v xs, Labelling k p) => p v (f v) -> q (t Field xs) (f (t Field xs))
- type FieldName k = forall v. LabelPhantom k v (Proxy v) -> Record `[k :> v]` -> Proxy (Record `[k :> v]`)
- fieldOptic :: forall proxy k. proxy k -> FieldOptic k
- type Record = (:*) Field
- (<:) :: h x -> (h :* xs) -> h :* (x : xs)
- data h :* s where
- type Variant = (:|) Field
- data LabelPhantom s a b
- type family Labelling s p :: Constraint
Documentation
module Data.Extensible.Class
module Data.Extensible.Inclusion
mkField :: String -> DecsQ Source
Generate fields using fieldOptic
.
defines:mkField
"foo bar"
foo :: FieldOptic "foo" bar :: FieldOptic "bar"
The type of fields.
type FieldOptic k = forall f p q t xs v. (Functor f, Profunctor p, Extensible f p q t, Associate k v xs, Labelling k p) => p v (f v) -> q (t Field xs) (f (t Field 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
type FieldName k = forall v. LabelPhantom k v (Proxy v) -> Record `[k :> v]` -> Proxy (Record `[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.
fieldOptic :: forall proxy k. proxy k -> FieldOptic k Source
Generate a field optic from the given name.
Records and variants
The type of extensible products.
Functor f => Extensible k * f (->) (->) ((:*) k) | |
Typeable ((k -> *) -> [k] -> *) ((:*) k) | |
WrapForall k * Eq h xs => Eq ((:*) k h xs) | |
(Eq ((:*) k h xs), WrapForall k * Ord h xs) => Ord ((:*) k h xs) | |
WrapForall k * Show h xs => Show ((:*) k h xs) | |
WrapForall k * Monoid h xs => Monoid ((:*) k h xs) |
Internal
data LabelPhantom s a b Source
A ghostly type which spells the field name
Extensible k k f (LabelPhantom k * k s) q t | |
Profunctor (LabelPhantom k * * s) |
type family Labelling s p :: Constraint Source
Labelling s (LabelPhantom t) = s ~ t | |
Labelling s p = () |