extensible-0.2.4: Poly-kinded, extensible ADTs

Copyright(c) Fumiaki Kinoshita 2015
LicenseBSD3
MaintainerFumiaki Kinoshita <fumiexcel@gmail.com>
Stabilityexperimental
Portabilitynon-portable
Safe HaskellNone
LanguageHaskell2010

Data.Extensible.Record

Contents

Description

Flexible records with well-typed fields. Example: https://github.com/fumieval/extensible/blob/master/examples/records.hs

Synopsis

Documentation

type Record = (:*) Field Source

The type of records which contain several fields

(<:*) :: forall h x xs. h x -> (h :* xs) -> h :* (x : xs) infixr 0 Source

O(log n) Add an element to a product.

data h :* s where Source

The extensible product type

Constructors

Nil :: h :* [] 

Instances

Typeable ((k -> *) -> [k] -> *) ((:*) k) 
Forall k (ClassComp * k Eq h) xs => Eq ((:*) k h xs) 
(Forall k (ClassComp * k Eq h) xs, Forall k (ClassComp * k Ord h) xs) => Ord ((:*) k h xs) 
(Show ((:*) k h xs), Show (h x)) => Show ((:*) k h ((:) k x xs)) 
Show ((:*) k h ([] k)) 

(@=) :: FieldName s -> FieldValue s -> Field s infix 1 Source

Annotate a value by the field name.

mkField :: String -> TypeQ -> DecsQ Source

Generate a field. mkField "foo" [t|Int|] defines:

type instance FieldValue "foo" = Int

foo :: FieldLens "foo"

The yielding field is a Lens.

data Field s Source

The type of fields.

Constructors

Field 

Fields

getField :: FieldValue s
 

Instances

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

When you see this type as an argument, it expects a FieldLens. This type hooks the name of FieldLens so that an expression field @= value has no ambiguousity.

Internal

class Labelable s p where Source

An internal class to characterize FieldLens

Methods

unlabel :: proxy s -> p a b -> a -> b Source

Instances

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

Instances

(~) k s t => Labelable k s (LabelPhantom k * * t)