vinyl-0.13.0: Extensible Records

Safe HaskellNone
LanguageHaskell2010

Data.Vinyl.XRec

Description

A variant of Rec whose values have eliminated common syntactic clutter due to Identity, Compose, and ElField type constructors.

A common pain point with using Rec is the mandatory context of each value. A basic record might look like this, Identity "joe" :& Identity 23 :& RNil :: Rec Identity '[String, Int]. The Identity constructors are a nuisance, so we offer a way of avoiding them: "joe" ::& 23 ::& XRNil :: XRec Identity '[String,Int]. Facilities are provided for converting between XRec and Rec so that the Rec API is available even if you choose to use XRec for construction or pattern matching.

Synopsis

Documentation

type XRec f = Rec (XData f) Source #

pattern (::&) :: HKD f r -> XRec f rs -> XRec f (r ': rs) infixr 7 Source #

pattern XRNil :: XRec f '[] Source #

rmapX :: forall f g rs. (XRMap f g rs, IsoXRec f rs, IsoXRec g rs) => (forall a. HKD f a -> HKD g a) -> Rec f rs -> Rec g rs Source #

Like rmap, but the supplied function is written against the HKD-simplified types. This is xrmap sandwiched in between fromXRec and toXRec.

rmapXEndo :: forall f rs. (XRMap f f rs, IsoXRec f rs) => (forall a. HKD f a -> HKD f a) -> Rec f rs -> Rec f rs Source #

This is rmapX specialized to a type at which it does not change interpretation functor. This can help with type inference.

xrmap :: forall f g rs. XRMap f g rs => (forall a. HKD f a -> HKD g a) -> XRec f rs -> XRec g rs Source #

This is rmap for XRec. We apply a natural transformation between interpretation functors to transport a record value between interpretations.

newtype XData t a Source #

A wrapper for an HKD-simplified value. That is, noisy value constructors like Identity and Compose are ellided. This is used in the xrmapAux type class method, but may be ignored by users whose needs are met by xrmap and rmapX.

Constructors

XData 

Fields

class XRMap f g rs where Source #

The implementation of xrmap is broken into a type class to permit unrolling of the recursion across a record. The function mapped across the vector hides the HKD type family under a newtype constructor to help the type checker.

Methods

xrmapAux :: (forall a. XData f a -> XData g a) -> XRec f rs -> XRec g rs Source #

Instances
XRMap (f :: u -> Type) (g :: u -> Type) ([] :: [u]) Source # 
Instance details

Defined in Data.Vinyl.XRec

Methods

xrmapAux :: (forall (a :: u0). XData f a -> XData g a) -> XRec f [] -> XRec g [] Source #

(XRMap f g rs, IsoHKD f r, IsoHKD g r) => XRMap (f :: a -> Type) (g :: a -> Type) (r ': rs :: [a]) Source # 
Instance details

Defined in Data.Vinyl.XRec

Methods

xrmapAux :: (forall (a0 :: u). XData f a0 -> XData g a0) -> XRec f (r ': rs) -> XRec g (r ': rs) Source #

class XRApply f g rs where Source #

Like rapply: record of components f r -> g r may be applied to a record of f to get a record of g.

Methods

xrapply :: XRec (Lift (->) f g) rs -> XRec f rs -> XRec g rs Source #

Instances
XRApply (f :: u -> Type) (g :: u -> Type) ([] :: [u]) Source # 
Instance details

Defined in Data.Vinyl.XRec

Methods

xrapply :: XRec (Lift (->) f g) [] -> XRec f [] -> XRec g [] Source #

XRApply f g rs => XRApply (f :: a -> Type) (g :: a -> Type) (r ': rs :: [a]) Source # 
Instance details

Defined in Data.Vinyl.XRec

Methods

xrapply :: XRec (Lift (->) f g) (r ': rs) -> XRec f (r ': rs) -> XRec g (r ': rs) Source #

class IsoXRec f ts where Source #

Conversion between XRec and Rec. It is convenient to build and consume XRec values to reduce syntactic noise, but Rec has a richer API that is difficult to build around the HKD type family.

Methods

fromXRec :: XRec f ts -> Rec f ts Source #

toXRec :: Rec f ts -> XRec f ts Source #

Instances
IsoXRec (f :: u -> Type) ([] :: [u]) Source # 
Instance details

Defined in Data.Vinyl.XRec

Methods

fromXRec :: XRec f [] -> Rec f [] Source #

toXRec :: Rec f [] -> XRec f [] Source #

(IsoXRec f ts, IsoHKD f t) => IsoXRec (f :: a -> Type) (t ': ts :: [a]) Source # 
Instance details

Defined in Data.Vinyl.XRec

Methods

fromXRec :: XRec f (t ': ts) -> Rec f (t ': ts) Source #

toXRec :: Rec f (t ': ts) -> XRec f (t ': ts) Source #

class IsoHKD f a where Source #

Isomorphism between a syntactically noisy value and a concise one. For types like, Identity, we prefer to work with values of the underlying type without writing out the Identity constructor. For Compose f g a, aka (f :. g) a, we prefer to work directly with values of type f (g a).

This involves the so-called higher-kinded data type family. See http://reasonablypolymorphic.com/blog/higher-kinded-data for more discussion.

Minimal complete definition

Nothing

Associated Types

type HKD f a Source #

Methods

unHKD :: HKD f a -> f a Source #

unHKD :: HKD f a ~ f a => HKD f a -> f a Source #

toHKD :: f a -> HKD f a Source #

toHKD :: HKD f a ~ f a => f a -> HKD f a Source #

Instances
(IsoHKD f (HKD g a), IsoHKD g a, Functor f) => IsoHKD (Compose f g :: k -> Type) (a :: k) Source #

Work with values of type Compose f g a as if they were of type f (g a).

Instance details

Defined in Data.Vinyl.XRec

Associated Types

type HKD (Compose f g) a :: Type Source #

Methods

unHKD :: HKD (Compose f g) a -> Compose f g a Source #

toHKD :: Compose f g a -> HKD (Compose f g) a Source #

(IsoHKD f a, IsoHKD g a) => IsoHKD (Lift ((->) :: Type -> Type -> Type) f g :: k -> Type) (a :: k) Source #

Work with values of type Lift (->) f g a as if they were of type f a -> g a.

Instance details

Defined in Data.Vinyl.XRec

Associated Types

type HKD (Lift (->) f g) a :: Type Source #

Methods

unHKD :: HKD (Lift (->) f g) a -> Lift (->) f g a Source #

toHKD :: Lift (->) f g a -> HKD (Lift (->) f g) a Source #

IsoHKD Maybe (a :: Type) Source # 
Instance details

Defined in Data.Vinyl.XRec

Associated Types

type HKD Maybe a :: Type Source #

Methods

unHKD :: HKD Maybe a -> Maybe a Source #

toHKD :: Maybe a -> HKD Maybe a Source #

IsoHKD IO (a :: Type) Source # 
Instance details

Defined in Data.Vinyl.XRec

Associated Types

type HKD IO a :: Type Source #

Methods

unHKD :: HKD IO a -> IO a Source #

toHKD :: IO a -> HKD IO a Source #

IsoHKD First (a :: Type) Source # 
Instance details

Defined in Data.Vinyl.XRec

Associated Types

type HKD First a :: Type Source #

Methods

unHKD :: HKD First a -> First a Source #

toHKD :: First a -> HKD First a Source #

IsoHKD Last (a :: Type) Source # 
Instance details

Defined in Data.Vinyl.XRec

Associated Types

type HKD Last a :: Type Source #

Methods

unHKD :: HKD Last a -> Last a Source #

toHKD :: Last a -> HKD Last a Source #

IsoHKD Sum (a :: Type) Source #

Work with values of type Sum a as if they were of type a.

Instance details

Defined in Data.Vinyl.XRec

Associated Types

type HKD Sum a :: Type Source #

Methods

unHKD :: HKD Sum a -> Sum a Source #

toHKD :: Sum a -> HKD Sum a Source #

IsoHKD Product (a :: Type) Source #

Work with values of type Product a as if they were of type a.

Instance details

Defined in Data.Vinyl.XRec

Associated Types

type HKD Product a :: Type Source #

IsoHKD Identity (a :: Type) Source #

Work with values of type Identity a as if they were simple of type a.

Instance details

Defined in Data.Vinyl.XRec

Associated Types

type HKD Identity a :: Type Source #

IsoHKD (Either a :: Type -> Type) (b :: Type) Source # 
Instance details

Defined in Data.Vinyl.XRec

Associated Types

type HKD (Either a) b :: Type Source #

Methods

unHKD :: HKD (Either a) b -> Either a b Source #

toHKD :: Either a b -> HKD (Either a) b Source #

IsoHKD ((,) a :: Type -> Type) (b :: Type) Source # 
Instance details

Defined in Data.Vinyl.XRec

Associated Types

type HKD ((,) a) b :: Type Source #

Methods

unHKD :: HKD ((,) a) b -> (a, b) Source #

toHKD :: (a, b) -> HKD ((,) a) b Source #

KnownSymbol s => IsoHKD ElField ((,) s a :: (Symbol, Type)) Source #

Work with values of type ElField '(s,a) as if they were of type a.

Instance details

Defined in Data.Vinyl.XRec

Associated Types

type HKD ElField (s, a) :: Type Source #

Methods

unHKD :: HKD ElField (s, a) -> ElField (s, a) Source #

toHKD :: ElField (s, a) -> HKD ElField (s, a) Source #

rgetX :: forall a record f rs. (RecElem record a a rs rs (RIndex a rs), RecElemFCtx record f, IsoHKD f a) => record f rs -> HKD f a Source #

Record field getter that pipes the field value through HKD to eliminate redundant newtype wrappings. Usage will typically involve a visible type application to the field type. The definition is similar to, getHKD = toHKD . rget.