Safe Haskell | None |
---|---|
Language | Haskell2010 |
Provides "syntax sugar" for constructing vinyl
records with
named fields, using GHC's OverloadedLabels extension.
This lets you create records using the following syntax, clearly associating each field's name with its value:
john ::Rec
ElField
['("name", String), '("age", Int)] john =rec_
#age 30 #name "John Doe"
You can also extend an existing record using extend_
:
john' ::Rec
ElField
['("bornAt", String), '("name", String), '("age", Int)] john' =extend_
john #bornAt "Zurich, Switzerland"
Synopsis
- rec_ :: RecSugarTy (Rec f '[]) o => o
- extend_ :: RecSugarTy (Rec f rs) o => Rec f rs -> o
- class NamedField (s :: Symbol) (r :: k) (f :: k -> Type) (a :: Type) | r -> s, r f -> a where
- toNamedField :: a -> f r
- class RecSugarTy e o | o -> e where
- rec' :: e -> o
- data FieldLabel (s :: Symbol) = FieldLabel
Record-construction sugar
rec_ :: RecSugarTy (Rec f '[]) o => o Source #
Create a record by adding fields to the empty record. This is the function you will use most of the time.
extend_ :: RecSugarTy (Rec f rs) o => Rec f rs -> o Source #
Create a record by extending an existing record.
Extending the syntax sugar
class NamedField (s :: Symbol) (r :: k) (f :: k -> Type) (a :: Type) | r -> s, r f -> a where Source #
Specifies how to convert a labeled value into an element of a
vinyl record. The only default instance is for
,
but you can define additional instances for your own interpretation
functors.ElField
toNamedField :: a -> f r Source #
Convert a value into a vinyl record element. You can imagine that this has the following type:
toNamedField :: KnownSymbol s => a -> ElField '(s, a)
Instances
(KnownSymbol s, s ~ s') => NamedField s' ((,) s a :: (Symbol, Type)) ElField a Source # | |
Defined in Data.Vinyl.Sugar toNamedField :: a -> ElField (s, a) Source # |
class RecSugarTy e o | o -> e where Source #
The workhorse class of this package. Implements a polyvariadic
function that builds up a
and converts it into
the desired output type.Rec
You can enable rec_
syntax for your own types by writing additional
RecSugarTy
instances, adding a base case to
. Example:rec'
data MyFunctor r -- elided newtype MyRec rs = MyRec { unMyRec ::Rec
MyFunctor rs } instanceRecSugarTy
(Rec
MyFunctor rs) (MyRec rs) where rec' = MyRec
Instances
(NamedField s r f a, RecSugarTy (Rec f (r ': rs)) o, lbl ~ FieldLabel s) => RecSugarTy (Rec f rs) (lbl -> a -> o) Source # | |
Defined in Data.Vinyl.Sugar | |
Storable (Rec f rs) => RecSugarTy (Rec f rs) (SRec f rs) Source # | |
NatToInt (RLength rs) => RecSugarTy (Rec f rs) (ARec f rs) Source # | |
RecSugarTy (Rec f rs) (Rec f rs) Source # | |
Auxiliary types
data FieldLabel (s :: Symbol) Source #
A simple proxy for type-level strings.