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 with well-typed fields. Example: https://github.com/fumieval/extensible/blob/master/examples/records.hs
- module Data.Extensible.Inclusion
- type Record = (:*) Field
- (<:*) :: forall h x xs. h x -> (h :* xs) -> h :* (x : xs)
- data h :* s where
- (@=) :: FieldName s -> FieldValue s -> Field s
- mkField :: String -> TypeQ -> DecsQ
- data Field s = Field {
- getField :: FieldValue s
- type family FieldValue s :: *
- type FieldLens s = forall f p xs. (Functor f, Labelable s p, s ∈ xs) => p (FieldValue s) (f (FieldValue s)) -> Record xs -> f (Record xs)
- type FieldName s = LabelPhantom s (FieldValue s) (Proxy (FieldValue s)) -> Record `[s]` -> Proxy (Record `[s]`)
- class Labelable s p where
- unlabel :: proxy s -> p a b -> a -> b
- data LabelPhantom s a b
Documentation
module Data.Extensible.Inclusion
(<:*) :: forall h x xs. h x -> (h :* xs) -> h :* (x : xs) infixr 0 Source
O(log n) Add an element to a product.
The extensible product type
(@=) :: FieldName s -> FieldValue s -> Field s infix 1 Source
Annotate a value by the field name.
The type of fields.
Field | |
|
(KnownSymbol s, Show (FieldValue s)) => Show (Field s) |
type family FieldValue s :: * Source
Associates names with concrete types.
type FieldLens s = forall f p xs. (Functor f, Labelable s p, s ∈ xs) => p (FieldValue s) (f (FieldValue s)) -> Record xs -> f (Record xs) Source
FieldLens s
is a type of lens that points a field named s
.
FieldLens
s = (s '∈' xs) => Lens' (Record
xs) (FieldValue
s)
type FieldName s = LabelPhantom s (FieldValue s) (Proxy (FieldValue s)) -> Record `[s]` -> Proxy (Record `[s]`) Source
Internal
class Labelable s p where Source
An internal class to characterize FieldLens
Labelable k s (->) | |
(~) k s t => Labelable k s (LabelPhantom k * * t) |
data LabelPhantom s a b Source
A ghostly type used to reify field names
(~) k s t => Labelable k s (LabelPhantom k * * t) |