vinyl-0.14.3: Extensible Records
Safe HaskellNone
LanguageHaskell2010

Data.Vinyl.ARec.Internal

Description

Constant-time field accessors for extensible records. The trade-off is the usual lists vs arrays one: it is fast to add an element to the head of a list, but element access is linear time; array access time is uniform, but extending the array is more slower.

Tradeoffs:

  • No sharing of the spine (i.e. when you change elements in the front of the record the tail can't be re-used)
  • ARec requires (4 + n) words + size of the fields
  • 1 for the ARec constructor
  • 1 for the pointer to the SmallArray#
  • The SmallArray# has 2 words as header (1 for GC, 1 for number of elements)
  • 1 pointer per element to the actual data
  • Rec requires (2n) words + size of Fields
  • 1 word per (:&) constructor
  • 1 word for the pointer to the element
Synopsis

Documentation

newtype ARec (f :: k -> *) (ts :: [k]) Source #

An array-backed extensible record with constant-time field access.

Constructors

ARec SmallArray 

Instances

Instances details
(is ~ RImage rs ss, IndexWitnesses is, NatToInt (RLength rs)) => RecSubset (ARec :: (k -> Type) -> [k] -> Type) (rs :: [k]) (ss :: [k]) is Source # 
Instance details

Defined in Data.Vinyl.ARec.Internal

Associated Types

type RecSubsetFCtx ARec f Source #

Methods

rsubsetC :: forall g (f :: k0 -> Type). (Functor g, RecSubsetFCtx ARec f) => (ARec f rs -> g (ARec f rs)) -> ARec f ss -> g (ARec f ss) Source #

rcastC :: forall (f :: k0 -> Type). RecSubsetFCtx ARec f => ARec f ss -> ARec f rs Source #

rreplaceC :: forall (f :: k0 -> Type). RecSubsetFCtx ARec f => ARec f rs -> ARec f ss -> ARec f ss Source #

RecElem (ARec :: (a -> Type) -> [a] -> Type) (t :: a) (t' :: a) (t ': ts :: [a]) (t' ': ts :: [a]) 'Z Source # 
Instance details

Defined in Data.Vinyl.ARec.Internal

Associated Types

type RecElemFCtx ARec f Source #

Methods

rlensC :: (Functor g, RecElemFCtx ARec f) => (f t -> g (f t')) -> ARec f (t ': ts) -> g (ARec f (t' ': ts)) Source #

rgetC :: (RecElemFCtx ARec f, t ~ t') => ARec f (t ': ts) -> f t Source #

rputC :: RecElemFCtx ARec f => f t' -> ARec f (t ': ts) -> ARec f (t' ': ts) Source #

(RIndex t (s ': ts) ~ 'S i, NatToInt i, RecElem (ARec :: (a -> Type) -> [a] -> Type) t t' ts ts' i) => RecElem (ARec :: (a -> Type) -> [a] -> Type) (t :: a) (t' :: a) (s ': ts :: [a]) (s ': ts' :: [a]) ('S i) Source # 
Instance details

Defined in Data.Vinyl.ARec.Internal

Associated Types

type RecElemFCtx ARec f Source #

Methods

rlensC :: (Functor g, RecElemFCtx ARec f) => (f t -> g (f t')) -> ARec f (s ': ts) -> g (ARec f (s ': ts')) Source #

rgetC :: (RecElemFCtx ARec f, t ~ t') => ARec f (s ': ts) -> f t Source #

rputC :: RecElemFCtx ARec f => f t' -> ARec f (s ': ts) -> ARec f (s ': ts') Source #

(RPureConstrained (IndexableField rs) rs, RecApplicative rs, Eq (Rec f rs)) => Eq (ARec f rs) Source # 
Instance details

Defined in Data.Vinyl.ARec.Internal

Methods

(==) :: ARec f rs -> ARec f rs -> Bool #

(/=) :: ARec f rs -> ARec f rs -> Bool #

(RPureConstrained (IndexableField rs) rs, RecApplicative rs, Ord (Rec f rs)) => Ord (ARec f rs) Source # 
Instance details

Defined in Data.Vinyl.ARec.Internal

Methods

compare :: ARec f rs -> ARec f rs -> Ordering #

(<) :: ARec f rs -> ARec f rs -> Bool #

(<=) :: ARec f rs -> ARec f rs -> Bool #

(>) :: ARec f rs -> ARec f rs -> Bool #

(>=) :: ARec f rs -> ARec f rs -> Bool #

max :: ARec f rs -> ARec f rs -> ARec f rs #

min :: ARec f rs -> ARec f rs -> ARec f rs #

(RPureConstrained (IndexableField rs) rs, RecApplicative rs, Show (Rec f rs)) => Show (ARec f rs) Source # 
Instance details

Defined in Data.Vinyl.ARec.Internal

Methods

showsPrec :: Int -> ARec f rs -> ShowS #

show :: ARec f rs -> String #

showList :: [ARec f rs] -> ShowS #

type RecSubsetFCtx (ARec :: (k -> Type) -> [k] -> Type) (f :: k -> Type) Source # 
Instance details

Defined in Data.Vinyl.ARec.Internal

type RecSubsetFCtx (ARec :: (k -> Type) -> [k] -> Type) (f :: k -> Type) = ()
type RecElemFCtx (ARec :: (a -> Type) -> [a] -> Type) (f :: a -> Type) Source # 
Instance details

Defined in Data.Vinyl.ARec.Internal

type RecElemFCtx (ARec :: (a -> Type) -> [a] -> Type) (f :: a -> Type) = ()
type RecElemFCtx (ARec :: (a -> Type) -> [a] -> Type) (f :: a -> Type) Source # 
Instance details

Defined in Data.Vinyl.ARec.Internal

type RecElemFCtx (ARec :: (a -> Type) -> [a] -> Type) (f :: a -> Type) = ()

class ToARec (us :: [k]) Source #

Minimal complete definition

aRecValues

Instances

Instances details
ToARec ('[] :: [k]) Source # 
Instance details

Defined in Data.Vinyl.ARec.Internal

Methods

aRecValues :: forall (f :: k0 -> Type). Rec f '[] -> ARecBuilder f '[]

ToARec us => ToARec (u ': us :: [k]) Source # 
Instance details

Defined in Data.Vinyl.ARec.Internal

Methods

aRecValues :: forall (f :: k0 -> Type). Rec f (u ': us) -> ARecBuilder f (u ': us)

class NatToInt (RIndex t ts) => IndexableField ts t Source #

Defines a constraint that lets us index into an ARec in order to produce a Rec using fromARec.

Instances

Instances details
NatToInt (RIndex t ts) => IndexableField (ts :: [k]) (t :: k) Source # 
Instance details

Defined in Data.Vinyl.ARec.Internal

arec :: forall k (us :: [k]) f. NatToInt (RLength us) => ARecBuilder f us -> ARec f us Source #

Turn an ARecBuilder into an ARec

See ARecBuilder

newtype ARecBuilder f us Source #

An efficient builder for ARec values

Use the pseudo-constructors arcons and arnil to construct an ARecBuilder and then turn it into an ARec with arec

Example: (requires -XOverloadedLabels and )

user :: ARec ElField '[ "name"   ::: String
                      , "age"    ::: Int
                      , "active" ::: Bool]
user = arec (  #name   =: "Peter"
            `arcons` #age    =: 4
            `arcons` #active =: True
            `arcons` arnil
            )

Constructors

ARecBuilder (forall s. Int -> SmallMutableArray s -> ST s ()) 

arcons :: f u -> ARecBuilder f us -> ARecBuilder f (u ': us) infixr 1 Source #

Pseudo-constructor for an ARecBuilder

Cons a field to an ARec under construction

See ARecBuilder

arnil :: ARecBuilder f '[] Source #

Pseudo-constructor for ARecBuilder

Build an ARec without fields

See ARecBuilder

toARec :: forall f ts. (NatToInt (RLength ts), ToARec ts) => Rec f ts -> ARec f ts Source #

Convert a Rec into an ARec for constant-time field access.

fromARec :: forall f ts. (RecApplicative ts, RPureConstrained (IndexableField ts) ts) => ARec f ts -> Rec f ts Source #

Convert an ARec into a Rec.

aget :: forall t f ts. NatToInt (RIndex t ts) => ARec f ts -> f t Source #

Get a field from an ARec.

unsafeAput :: forall t t' f ts ts'. NatToInt (RIndex t ts) => f t' -> ARec f ts -> ARec f ts' Source #

Set a field in an ARec.

unsafeAlens :: forall f g t t' ts ts'. (Functor g, NatToInt (RIndex t ts)) => (f t -> g (f t')) -> ARec f ts -> g (ARec f ts') Source #

Define a lens for a field of an ARec.

arecGetSubset :: forall rs ss f. (IndexWitnesses (RImage rs ss), NatToInt (RLength rs)) => ARec f ss -> ARec f rs Source #

Get a subset of a record's fields.

arecSetSubset :: forall rs ss f. IndexWitnesses (RImage rs ss) => ARec f ss -> ARec f rs -> ARec f ss Source #

Set a subset of a larger record's fields to all of the fields of a smaller record.

arecRepsMatchCoercion :: AllRepsMatch f xs g ys => Coercion (ARec f xs) (ARec g ys) Source #

Given that xs and ys have the same length, and mapping f over xs and g over ys produces lists whose elements are pairwise Coercible, ARec f xs and ARec g ys are Coercible.

arecConsMatchCoercion :: (forall (x :: k). Coercible (f x) (g x)) => Coercion (ARec f xs) (ARec g xs) Source #

Given that forall x. Coercible (f x) (g x), produce a coercion from ARec f xs to ARec g xs. While the constraint looks a lot like Coercible f g, it is actually weaker.