red-black-record-1.0.0.2: Extensible records and variants indexed by a type-level Red-Black tree.

Safe HaskellNone
LanguageHaskell2010

Data.RBR.Internal

Synopsis

Documentation

data Color Source #

The color of a node.

Constructors

R 
B 
Instances
Show Color Source # 
Instance details

Defined in Data.RBR.Internal

Methods

showsPrec :: Int -> Color -> ShowS #

show :: Color -> String #

showList :: [Color] -> ShowS #

data RBT k v Source #

The Red-Black tree. It will be used, as a kind, to index the Record and Variant types.

Constructors

E 
N Color (RBT k v) k v (RBT k v) 
Instances
(Show k, Show v) => Show (RBT k v) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

showsPrec :: Int -> RBT k v -> ShowS #

show :: RBT k v -> String #

showList :: [RBT k v] -> ShowS #

type family KeysValuesAllF (c :: k -> v -> Constraint) (t :: RBT k v) :: Constraint where ... Source #

Equations

KeysValuesAllF _ E = () 
KeysValuesAllF c (N color left k v right) = (c k v, KeysValuesAll c left, KeysValuesAll c right) 

class KeysValuesAllF c t => KeysValuesAll (c :: k -> v -> Constraint) (t :: RBT k v) where Source #

Require a constraint for every key-value pair in a tree. This is a generalization of All from Data.SOP.

cpara_RBT constructs a Record by means of a constraint for producing the nodes of the tree. The constraint is passed as a Proxy. This function seldom needs to be called directly.

Methods

cpara_RBT :: proxy c -> r E -> (forall left k v right color. (c k v, KeysValuesAll c left, KeysValuesAll c right) => r left -> r right -> r (N color left k v right)) -> r t Source #

Instances
KeysValuesAll (c :: k -> v -> Constraint) (E :: RBT k v) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

cpara_RBT :: proxy c -> r E -> (forall (left :: RBT k0 v0) (k1 :: k0) (v1 :: v0) (right :: RBT k0 v0) (color :: Color). (c k1 v1, KeysValuesAll c left, KeysValuesAll c right) => r left -> r right -> r (N color left k1 v1 right)) -> r E Source #

(c k2 v2, KeysValuesAll c left, KeysValuesAll c right) => KeysValuesAll (c :: k1 -> v1 -> Constraint) (N color left k2 v2 right :: RBT k1 v1) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

cpara_RBT :: proxy c -> r E -> (forall (left0 :: RBT k v) (k :: k) (v :: v) (right0 :: RBT k v) (color0 :: Color). (c k v, KeysValuesAll c left0, KeysValuesAll c right0) => r left0 -> r right0 -> r (N color0 left0 k v right0)) -> r (N color left k2 v2 right) Source #

demoteKeys :: forall t. KeysValuesAll KnownKey t => Record (K String) t Source #

Create a Record containing the names of each field.

The names are represented by a constant functor K carrying an annotation of type String. This means that there aren't actually any of the type that corresponds to each field, only the String annotations.

class KnownSymbol k => KnownKey (k :: Symbol) (v :: z) Source #

Instances
KnownSymbol k => KnownKey k (v :: z) Source # 
Instance details

Defined in Data.RBR.Internal

data Record (f :: Type -> Type) (t :: RBT Symbol Type) where Source #

An extensible product-like type with named fields.

The values in the Record come wrapped in a type constructor f, which por pure records will be the identity functor I.

Constructors

Empty :: Record f E 
Node :: Record f left -> f v -> Record f right -> Record f (N color left k v right) 
Instances
(Productlike ([] :: [Type]) t result, Show (NP f result)) => Show (Record f t) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

showsPrec :: Int -> Record f t -> ShowS #

show :: Record f t -> String #

showList :: [Record f t] -> ShowS #

prettyShowRecord :: forall t flat f. (KeysValuesAll KnownKey t, Productlike '[] t flat, All Show flat, SListI flat) => (forall x. Show x => f x -> String) -> Record f t -> String Source #

Show a Record in a friendlier way than the default Show instance. The function argument will usually be show, but it can be used to unwrap the value of each field before showing it.

prettyShowRecordI :: forall t flat. (KeysValuesAll KnownKey t, Productlike '[] t flat, All Show flat, SListI flat) => Record I t -> String Source #

Like prettyShowRecord but specialized to pure records.

unit :: Record f E Source #

A Record without components is a boring, uninformative type whose single value can be conjured out of thin air.

data Variant (f :: Type -> Type) (t :: RBT Symbol Type) where Source #

An extensible sum-like type with named branches.

The values in the Variant come wrapped in a type constructor f, which por pure variants will be the identity functor I.

Constructors

Here :: f v -> Variant f (N color left k v right) 
LookRight :: Variant f t -> Variant f (N color' left' k' v' t) 
LookLeft :: Variant f t -> Variant f (N color' t k' v' right') 
Instances
(Sumlike ([] :: [Type]) t result, Show (NS f result)) => Show (Variant f t) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

showsPrec :: Int -> Variant f t -> ShowS #

show :: Variant f t -> String #

showList :: [Variant f t] -> ShowS #

impossible :: Variant f E -> b Source #

A Variant without branches doesn't have any values. From an impossible thing, anything can come out.

prettyShowVariant :: forall t flat f. (KeysValuesAll KnownKey t, Productlike '[] t flat, Sumlike '[] t flat, All Show flat, SListI flat) => (forall x. Show x => f x -> String) -> Variant f t -> String Source #

Show a Variant in a friendlier way than the default Show instance. The function argument will usually be show, but it can be used to unwrap the value of the branch before showing it.

prettyShowVariantI :: forall t flat. (KeysValuesAll KnownKey t, Productlike '[] t flat, Sumlike '[] t flat, All Show flat, SListI flat) => Variant I t -> String Source #

Like prettyShowVariant but specialized to pure variants.

type family InsertAll (es :: [(Symbol, Type)]) (t :: RBT Symbol Type) :: RBT Symbol Type where ... Source #

Insert a list of type level key / value pairs into a type-level tree.

Equations

InsertAll '[] t = t 
InsertAll ('(name, fieldType) ': es) t = Insert name fieldType (InsertAll es t) 

type FromList (es :: [(Symbol, Type)]) = InsertAll es E Source #

Build a type-level tree out of a list of type level key / value pairs.

addField :: forall k v t f. Insertable k v t => f v -> Record f t -> Record f (Insert k v t) Source #

Alias for insert.

insertI :: forall k v t. Insertable k v t => v -> Record I t -> Record I (Insert k v t) Source #

Like insert but specialized to pure Records.

addFieldI :: forall k v t. Insertable k v t => v -> Record I t -> Record I (Insert k v t) Source #

Like addField but specialized to pure Records.

class Insertable (k :: Symbol) (v :: Type) (t :: RBT Symbol Type) where Source #

Class that determines if the pair of a Symbol key and a Type can be inserted into a type-level tree.

The associated type family Insert produces the resulting tree.

At the term level, this manifests in insert, which adds a new field to a record, and in widen, which lets you use a Variant in a bigger context than the one in which is was defined. insert tends to be more useful in practice.

If the tree already has the key but with a different type, the insertion fails to compile.

Associated Types

type Insert k v t :: RBT Symbol Type Source #

Methods

insert :: f v -> Record f t -> Record f (Insert k v t) Source #

widen :: Variant f t -> Variant f (Insert k v t) Source #

Instances
(InsertableHelper1 k v t, CanMakeBlack (Insert1 k v t)) => Insertable k v t Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Insert k v t :: RBT Symbol Type Source #

Methods

insert :: f v -> Record f t -> Record f (Insert k v t) Source #

widen :: Variant f t -> Variant f (Insert k v t) Source #

class CanMakeBlack (t :: RBT Symbol Type) where Source #

Associated Types

type MakeBlack t :: RBT Symbol Type Source #

Instances
CanMakeBlack (N color left k v right) Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type MakeBlack (N color left k v right) :: RBT Symbol Type Source #

Methods

makeBlackR :: Record f (N color left k v right) -> Record f (MakeBlack (N color left k v right)) Source #

makeBlackV :: Variant f (N color left k v right) -> Variant f (MakeBlack (N color left k v right)) Source #

class InsertableHelper1 (k :: Symbol) (v :: Type) (t :: RBT Symbol Type) where Source #

Associated Types

type Insert1 k v t :: RBT Symbol Type Source #

Methods

insert1 :: f v -> Record f t -> Record f (Insert1 k v t) Source #

widen1 :: Variant f t -> Variant f (Insert1 k v t) Source #

Instances
InsertableHelper1 k v (E :: RBT Symbol Type) Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Insert1 k v E :: RBT Symbol Type Source #

Methods

insert1 :: f v -> Record f E -> Record f (Insert1 k v E) Source #

widen1 :: Variant f E -> Variant f (Insert1 k v E) Source #

(CmpSymbol k k' ~ ordering, InsertableHelper2 ordering k v color left k' v' right) => InsertableHelper1 k v (N color left k' v' right) Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Insert1 k v (N color left k' v' right) :: RBT Symbol Type Source #

Methods

insert1 :: f v -> Record f (N color left k' v' right) -> Record f (Insert1 k v (N color left k' v' right)) Source #

widen1 :: Variant f (N color left k' v' right) -> Variant f (Insert1 k v (N color left k' v' right)) Source #

class InsertableHelper2 (ordering :: Ordering) (k :: Symbol) (v :: Type) (color :: Color) (left :: RBT Symbol Type) (k' :: Symbol) (v' :: Type) (right :: RBT Symbol Type) where Source #

Associated Types

type Insert2 ordering k v color left k' v' right :: RBT Symbol Type Source #

Methods

insert2 :: f v -> Record f (N color left k' v' right) -> Record f (Insert2 ordering k v color left k' v' right) Source #

widen2 :: Variant f (N color left k' v' right) -> Variant f (Insert2 ordering k v color left k' v' right) Source #

Instances
(InsertableHelper1 k v left, Balanceable color (Insert1 k v left) k' v' right) => InsertableHelper2 LT k v color left k' v' right Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Insert2 LT k v color left k' v' right :: RBT Symbol Type Source #

Methods

insert2 :: f v -> Record f (N color left k' v' right) -> Record f (Insert2 LT k v color left k' v' right) Source #

widen2 :: Variant f (N color left k' v' right) -> Variant f (Insert2 LT k v color left k' v' right) Source #

InsertableHelper2 EQ k v color left k v right Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Insert2 EQ k v color left k v right :: RBT Symbol Type Source #

Methods

insert2 :: f v -> Record f (N color left k v right) -> Record f (Insert2 EQ k v color left k v right) Source #

widen2 :: Variant f (N color left k v right) -> Variant f (Insert2 EQ k v color left k v right) Source #

(InsertableHelper1 k v right, Balanceable color left k' v' (Insert1 k v right)) => InsertableHelper2 GT k v color left k' v' right Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Insert2 GT k v color left k' v' right :: RBT Symbol Type Source #

Methods

insert2 :: f v -> Record f (N color left k' v' right) -> Record f (Insert2 GT k v color left k' v' right) Source #

widen2 :: Variant f (N color left k' v' right) -> Variant f (Insert2 GT k v color left k' v' right) Source #

type family ShouldBalance (color :: Color) (left :: RBT k' v') (right :: RBT k' v') :: BalanceAction where ... Source #

Equations

ShouldBalance B (N R (N R _ _ _ _) _ _ _) _ = BalanceLL 
ShouldBalance B (N R _ _ _ (N R _ _ _ _)) _ = BalanceLR 
ShouldBalance B _ (N R (N R _ _ _ _) _ _ _) = BalanceRL 
ShouldBalance B _ (N R _ _ _ (N R _ _ _ _)) = BalanceRR 
ShouldBalance _ _ _ = DoNotBalance 

class Balanceable (color :: Color) (left :: RBT Symbol Type) (k :: Symbol) (v :: Type) (right :: RBT Symbol Type) where Source #

Associated Types

type Balance color left k v right :: RBT Symbol Type Source #

Methods

balanceR :: Record f (N color left k v right) -> Record f (Balance color left k v right) Source #

balanceV :: Variant f (N color left k v right) -> Variant f (Balance color left k v right) Source #

Instances
(ShouldBalance color left right ~ action, BalanceableHelper action color left k v right) => Balanceable color left k v right Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Balance color left k v right :: RBT Symbol Type Source #

Methods

balanceR :: Record f (N color left k v right) -> Record f (Balance color left k v right) Source #

balanceV :: Variant f (N color left k v right) -> Variant f (Balance color left k v right) Source #

class BalanceableHelper (action :: BalanceAction) (color :: Color) (left :: RBT Symbol Type) (k :: Symbol) (v :: Type) (right :: RBT Symbol Type) where Source #

Associated Types

type Balance' action color left k v right :: RBT Symbol Type Source #

Methods

balanceR' :: Record f (N color left k v right) -> Record f (Balance' action color left k v right) Source #

balanceV' :: Variant f (N color left k v right) -> Variant f (Balance' action color left k v right) Source #

Instances
BalanceableHelper DoNotBalance color a k v b Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Balance' DoNotBalance color a k v b :: RBT Symbol Type Source #

Methods

balanceR' :: Record f (N color a k v b) -> Record f (Balance' DoNotBalance color a k v b) Source #

balanceV' :: Variant f (N color a k v b) -> Variant f (Balance' DoNotBalance color a k v b) Source #

BalanceableHelper BalanceRL B a k1 v1 (N R (N R b k2 v2 c) k3 v3 d) Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Balance' BalanceRL B a k1 v1 (N R (N R b k2 v2 c) k3 v3 d) :: RBT Symbol Type Source #

Methods

balanceR' :: Record f (N B a k1 v1 (N R (N R b k2 v2 c) k3 v3 d)) -> Record f (Balance' BalanceRL B a k1 v1 (N R (N R b k2 v2 c) k3 v3 d)) Source #

balanceV' :: Variant f (N B a k1 v1 (N R (N R b k2 v2 c) k3 v3 d)) -> Variant f (Balance' BalanceRL B a k1 v1 (N R (N R b k2 v2 c) k3 v3 d)) Source #

BalanceableHelper BalanceRR B a k1 v1 (N R b k2 v2 (N R c k3 v3 d)) Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Balance' BalanceRR B a k1 v1 (N R b k2 v2 (N R c k3 v3 d)) :: RBT Symbol Type Source #

Methods

balanceR' :: Record f (N B a k1 v1 (N R b k2 v2 (N R c k3 v3 d))) -> Record f (Balance' BalanceRR B a k1 v1 (N R b k2 v2 (N R c k3 v3 d))) Source #

balanceV' :: Variant f (N B a k1 v1 (N R b k2 v2 (N R c k3 v3 d))) -> Variant f (Balance' BalanceRR B a k1 v1 (N R b k2 v2 (N R c k3 v3 d))) Source #

BalanceableHelper BalanceLL B (N R (N R a k1 v1 b) k2 v2 c) k3 v3 d Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Balance' BalanceLL B (N R (N R a k1 v1 b) k2 v2 c) k3 v3 d :: RBT Symbol Type Source #

Methods

balanceR' :: Record f (N B (N R (N R a k1 v1 b) k2 v2 c) k3 v3 d) -> Record f (Balance' BalanceLL B (N R (N R a k1 v1 b) k2 v2 c) k3 v3 d) Source #

balanceV' :: Variant f (N B (N R (N R a k1 v1 b) k2 v2 c) k3 v3 d) -> Variant f (Balance' BalanceLL B (N R (N R a k1 v1 b) k2 v2 c) k3 v3 d) Source #

BalanceableHelper BalanceLR B (N R a k1 v1 (N R b k2 v2 c)) k3 v3 d Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Balance' BalanceLR B (N R a k1 v1 (N R b k2 v2 c)) k3 v3 d :: RBT Symbol Type Source #

Methods

balanceR' :: Record f (N B (N R a k1 v1 (N R b k2 v2 c)) k3 v3 d) -> Record f (Balance' BalanceLR B (N R a k1 v1 (N R b k2 v2 c)) k3 v3 d) Source #

balanceV' :: Variant f (N B (N R a k1 v1 (N R b k2 v2 c)) k3 v3 d) -> Variant f (Balance' BalanceLR B (N R a k1 v1 (N R b k2 v2 c)) k3 v3 d) Source #

class Key (k :: Symbol) (t :: RBT Symbol Type) where Source #

Class that determines if a given Symbol key is present in a type-level tree.

The Value type family gives the Type corresponding to the key.

field takes a field name (given through TypeApplications) and a Record, and returns a pair of a setter for the field and the original value of the field.

branch takes a branch name (given through TypeApplications) and returns a pair of a match function and a constructor.

Associated Types

type Value k t :: Type Source #

Methods

field :: Record f t -> (f (Value k t) -> Record f t, f (Value k t)) Source #

branch :: (Variant f t -> Maybe (f (Value k t)), f (Value k t) -> Variant f t) Source #

Instances
(CmpSymbol k' k ~ ordering, KeyHelper ordering k left v' right) => Key k (N color left k' v' right) Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Value k (N color left k' v' right) :: Type Source #

Methods

field :: Record f (N color left k' v' right) -> (f (Value k (N color left k' v' right)) -> Record f (N color left k' v' right), f (Value k (N color left k' v' right))) Source #

branch :: (Variant f (N color left k' v' right) -> Maybe (f (Value k (N color left k' v' right))), f (Value k (N color left k' v' right)) -> Variant f (N color left k' v' right)) Source #

class KeyHelper (ordering :: Ordering) (k :: Symbol) (left :: RBT Symbol Type) (v :: Type) (right :: RBT Symbol Type) where Source #

Associated Types

type Value' ordering k left v right :: Type Source #

Methods

field' :: Record f (N colorx left kx v right) -> (f (Value' ordering k left v right) -> Record f (N colorx left kx v right), f (Value' ordering k left v right)) Source #

branch' :: (Variant f (N colorx left kx v right) -> Maybe (f (Value' ordering k left v right)), f (Value' ordering k left v right) -> Variant f (N colorx left kx v right)) Source #

Instances
KeyHelper EQ k left v right Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Value' EQ k left v right :: Type Source #

Methods

field' :: Record f (N colorx left kx v right) -> (f (Value' EQ k left v right) -> Record f (N colorx left kx v right), f (Value' EQ k left v right)) Source #

branch' :: (Variant f (N colorx left kx v right) -> Maybe (f (Value' EQ k left v right)), f (Value' EQ k left v right) -> Variant f (N colorx left kx v right)) Source #

(CmpSymbol k2 k ~ ordering, KeyHelper ordering k left2 v2 right2) => KeyHelper LT k left v (N color2 left2 k2 v2 right2) Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Value' LT k left v (N color2 left2 k2 v2 right2) :: Type Source #

Methods

field' :: Record f (N colorx left kx v (N color2 left2 k2 v2 right2)) -> (f (Value' LT k left v (N color2 left2 k2 v2 right2)) -> Record f (N colorx left kx v (N color2 left2 k2 v2 right2)), f (Value' LT k left v (N color2 left2 k2 v2 right2))) Source #

branch' :: (Variant f (N colorx left kx v (N color2 left2 k2 v2 right2)) -> Maybe (f (Value' LT k left v (N color2 left2 k2 v2 right2))), f (Value' LT k left v (N color2 left2 k2 v2 right2)) -> Variant f (N colorx left kx v (N color2 left2 k2 v2 right2))) Source #

(CmpSymbol k2 k ~ ordering, KeyHelper ordering k left2 v2 right2) => KeyHelper GT k (N color2 left2 k2 v2 right2) v' right Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type Value' GT k (N color2 left2 k2 v2 right2) v' right :: Type Source #

Methods

field' :: Record f (N colorx (N color2 left2 k2 v2 right2) kx v' right) -> (f (Value' GT k (N color2 left2 k2 v2 right2) v' right) -> Record f (N colorx (N color2 left2 k2 v2 right2) kx v' right), f (Value' GT k (N color2 left2 k2 v2 right2) v' right)) Source #

branch' :: (Variant f (N colorx (N color2 left2 k2 v2 right2) kx v' right) -> Maybe (f (Value' GT k (N color2 left2 k2 v2 right2) v' right)), f (Value' GT k (N color2 left2 k2 v2 right2) v' right) -> Variant f (N colorx (N color2 left2 k2 v2 right2) kx v' right)) Source #

project :: forall k t f. Key k t => Record f t -> f (Value k t) Source #

Get the value of a field for a Record.

getField :: forall k t f. Key k t => Record f t -> f (Value k t) Source #

Alias for project.

setField :: forall k t f. Key k t => f (Value k t) -> Record f t -> Record f t Source #

Set the value of a field for a Record.

modifyField :: forall k t f. Key k t => (f (Value k t) -> f (Value k t)) -> Record f t -> Record f t Source #

Modify the value of a field for a Record.

inject :: forall k t f. Key k t => f (Value k t) -> Variant f t Source #

Put a value into the branch of a Variant.

match :: forall k t f. Key k t => Variant f t -> Maybe (f (Value k t)) Source #

Check if a Variant value is the given branch.

projectI :: forall k t. Key k t => Record I t -> Value k t Source #

Like project but specialized to pure Records.

getFieldI :: forall k t. Key k t => Record I t -> Value k t Source #

Like getField but specialized to pure Records.

setFieldI :: forall k t. Key k t => Value k t -> Record I t -> Record I t Source #

Like setField but specialized to pure Records.

modifyFieldI :: forall k t. Key k t => (Value k t -> Value k t) -> Record I t -> Record I t Source #

Like modifyField but specialized to pure Records.

injectI :: forall k t. Key k t => Value k t -> Variant I t Source #

Like inject but specialized to pure Variants.

matchI :: forall k t. Key k t => Variant I t -> Maybe (Value k t) Source #

Like match but specialized to pure Variantss.

eliminate :: (Productlike '[] t result, Sumlike '[] t result, SListI result) => Record (Case f r) t -> Variant f t -> r Source #

Process a Variant using a eliminator Record that carries handlers for each possible branch of the Variant.

newtype Case f a b Source #

Represents a handler for a branch of a Variant.

Constructors

Case (f b -> a) 

addCase :: forall k v t f a. Insertable k v t => (f v -> a) -> Record (Case f a) t -> Record (Case f a) (Insert k v t) Source #

A form of addField for creating eliminators for Variants.

addCaseI :: forall k v t a. Insertable k v t => (v -> a) -> Record (Case I a) t -> Record (Case I a) (Insert k v t) Source #

A pure version of addCase.

newtype SetField f a b Source #

Constructors

SetField 

Fields

class (Key k t, Value k t ~ v) => PresentIn (t :: RBT Symbol Type) (k :: Symbol) (v :: Type) Source #

Instances
(Key k t, Value k t ~ v) => PresentIn t k v Source # 
Instance details

Defined in Data.RBR.Internal

type ProductlikeSubset (subset :: RBT Symbol Type) (whole :: RBT Symbol Type) (flat :: [Type]) = (KeysValuesAll (PresentIn whole) subset, Productlike '[] subset flat, SListI flat) Source #

Constraint for trees that represent subsets of fields of Record-like types.

fieldSubset :: forall subset whole flat f. ProductlikeSubset subset whole flat => Record f whole -> (Record f subset -> Record f whole, Record f subset) Source #

Like field, but targets multiple fields at the same time

projectSubset :: forall subset whole flat f. ProductlikeSubset subset whole flat => Record f whole -> Record f subset Source #

Like project, but extracts multiple fields at the same time.

Can also be used to convert between structurally dissimilar trees that nevertheless have the same entries.

getFieldSubset :: forall subset whole flat f. ProductlikeSubset subset whole flat => Record f whole -> Record f subset Source #

Alias for projectSubset.

setFieldSubset :: forall subset whole flat f. ProductlikeSubset subset whole flat => Record f subset -> Record f whole -> Record f whole Source #

Like setField, but sets multiple fields at the same time.

modifyFieldSubset :: forall subset whole flat f. ProductlikeSubset subset whole flat => (Record f subset -> Record f subset) -> Record f whole -> Record f whole Source #

Like modifyField, but modifies multiple fields at the same time.

type SumlikeSubset (subset :: RBT Symbol Type) (whole :: RBT Symbol Type) (subflat :: [Type]) (wholeflat :: [Type]) = (KeysValuesAll (PresentIn whole) subset, Productlike '[] whole wholeflat, Sumlike '[] whole wholeflat, SListI wholeflat, Productlike '[] subset subflat, Sumlike '[] subset subflat, SListI subflat) Source #

Constraint for trees that represent subsets of branches of Variant-like types.

branchSubset :: forall subset whole subflat wholeflat f. SumlikeSubset subset whole subflat wholeflat => (Variant f whole -> Maybe (Variant f subset), Variant f subset -> Variant f whole) Source #

Like branch, but targets multiple branches at the same time.

injectSubset :: forall subset whole subflat wholeflat f. SumlikeSubset subset whole subflat wholeflat => Variant f subset -> Variant f whole Source #

Like inject, but injects one of several possible branches.

matchSubset :: forall subset whole subflat wholeflat f. SumlikeSubset subset whole subflat wholeflat => Variant f whole -> Maybe (Variant f subset) Source #

Like match, but matches more than one branch.

eliminateSubset :: forall subset whole subflat wholeflat f r. SumlikeSubset subset whole subflat wholeflat => Record (Case f r) whole -> Variant f subset -> r Source #

Like eliminate, but allows the eliminator Record to have more fields than there are branches in the Variant.

class Productlike (start :: [Type]) (t :: RBT Symbol Type) (result :: [Type]) | start t -> result, result t -> start where Source #

Class from converting Records to and from the n-ary product type NP from Data.SOP.

prefixNP flattens a Record and adds it to the initial part of the product.

breakNP reconstructs a Record from the initial part of the product and returns the unconsumed part.

The functions toNP and fromNP are usually easier to use.

Methods

prefixNP :: Record f t -> NP f start -> NP f result Source #

breakNP :: NP f result -> (Record f t, NP f start) Source #

Instances
Productlike start (E :: RBT Symbol Type) start Source # 
Instance details

Defined in Data.RBR.Internal

Methods

prefixNP :: Record f E -> NP f start -> NP f start Source #

breakNP :: NP f start -> (Record f E, NP f start) Source #

(Productlike start right middle, Productlike (v ': middle) left result) => Productlike start (N color left k v right) result Source # 
Instance details

Defined in Data.RBR.Internal

Methods

prefixNP :: Record f (N color left k v right) -> NP f start -> NP f result Source #

breakNP :: NP f result -> (Record f (N color left k v right), NP f start) Source #

toNP :: forall t result f. Productlike '[] t result => Record f t -> NP f result Source #

Convert a Record into a n-ary product.

fromNP :: forall t result f. Productlike '[] t result => NP f result -> Record f t Source #

Convert a n-ary product into a compatible Record.

class Sumlike (start :: [Type]) (t :: RBT Symbol Type) (result :: [Type]) | start t -> result, result t -> start where Source #

Class from converting Variants to and from the n-ary sum type NS from Data.SOP.

prefixNS flattens a Variant and adds it to the initial part of the sum.

breakNS reconstructs a Variant from the initial part of the sum and returns the unconsumed part.

The functions toNS and fromNS are usually easier to use.

Methods

prefixNS :: Either (NS f start) (Variant f t) -> NS f result Source #

breakNS :: NS f result -> Either (NS f start) (Variant f t) Source #

Instances
Sumlike (v ': start) (N colorL leftL kL vL rightL) result => Sumlike start (N color (N colorL leftL kL vL rightL) k v (E :: RBT Symbol Type)) result Source # 
Instance details

Defined in Data.RBR.Internal

Methods

prefixNS :: Either (NS f start) (Variant f (N color (N colorL leftL kL vL rightL) k v E)) -> NS f result Source #

breakNS :: NS f result -> Either (NS f start) (Variant f (N color (N colorL leftL kL vL rightL) k v E)) Source #

(Sumlike start (N colorR leftR kR vR rightR) middle, Sumlike (v ': middle) (N colorL leftL kL vL rightL) result) => Sumlike start (N color (N colorL leftL kL vL rightL) k v (N colorR leftR kR vR rightR)) result Source # 
Instance details

Defined in Data.RBR.Internal

Methods

prefixNS :: Either (NS f start) (Variant f (N color (N colorL leftL kL vL rightL) k v (N colorR leftR kR vR rightR))) -> NS f result Source #

breakNS :: NS f result -> Either (NS f start) (Variant f (N color (N colorL leftL kL vL rightL) k v (N colorR leftR kR vR rightR))) Source #

Sumlike start (N colorR leftR kR vR rightR) middle => Sumlike start (N color (E :: RBT Symbol Type) k v (N colorR leftR kR vR rightR)) (v ': middle) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

prefixNS :: Either (NS f start) (Variant f (N color E k v (N colorR leftR kR vR rightR))) -> NS f (v ': middle) Source #

breakNS :: NS f (v ': middle) -> Either (NS f start) (Variant f (N color E k v (N colorR leftR kR vR rightR))) Source #

Sumlike start (N color (E :: RBT Symbol Type) k v (E :: RBT Symbol Type)) (v ': start) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

prefixNS :: Either (NS f start) (Variant f (N color E k v E)) -> NS f (v ': start) Source #

breakNS :: NS f (v ': start) -> Either (NS f start) (Variant f (N color E k v E)) Source #

toNS :: forall t result f. Sumlike '[] t result => Variant f t -> NS f result Source #

Convert a Variant into a n-ary sum.

fromNS :: forall t result f. Sumlike '[] t result => NS f result -> Variant f t Source #

Convert a n-ary sum into a compatible Variant.

class ToRecord (r :: Type) where Source #

Minimal complete definition

Nothing

Associated Types

type RecordCode r :: RBT Symbol Type Source #

class ToRecordHelper (start :: RBT Symbol Type) (g :: Type -> Type) where Source #

Associated Types

type RecordCode' start g :: RBT Symbol Type Source #

Methods

toRecord' :: Record I start -> g x -> Record I (RecordCode' start g) Source #

Instances
(ToRecordHelper start t2, RecordCode' start t2 ~ middle, ToRecordHelper middle t1) => ToRecordHelper start (t1 :*: t2) Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type RecordCode' start (t1 :*: t2) :: RBT Symbol Type Source #

Methods

toRecord' :: Record I start -> (t1 :*: t2) x -> Record I (RecordCode' start (t1 :*: t2)) Source #

Insertable k v start => ToRecordHelper start (S1 (MetaSel (Just k) unpackedness strictness laziness) (Rec0 v)) Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type RecordCode' start (S1 (MetaSel (Just k) unpackedness strictness laziness) (Rec0 v)) :: RBT Symbol Type Source #

Methods

toRecord' :: Record I start -> S1 (MetaSel (Just k) unpackedness strictness laziness) (Rec0 v) x -> Record I (RecordCode' start (S1 (MetaSel (Just k) unpackedness strictness laziness) (Rec0 v))) Source #

ToRecordHelper (E :: RBT Symbol Type) fields => ToRecordHelper (E :: RBT Symbol Type) (D1 meta (C1 metacons fields)) Source # 
Instance details

Defined in Data.RBR.Internal

Associated Types

type RecordCode' E (D1 meta (C1 metacons fields)) :: RBT Symbol Type Source #

Methods

toRecord' :: Record I E -> D1 meta (C1 metacons fields) x -> Record I (RecordCode' E (D1 meta (C1 metacons fields))) Source #

class ToRecord r => FromRecord (r :: Type) where Source #

Minimal complete definition

Nothing

class FromRecordHelper (t :: RBT Symbol Type) (g :: Type -> Type) where Source #

Methods

fromRecord' :: Record I t -> g x Source #

Instances
(FromRecordHelper t t1, FromRecordHelper t t2) => FromRecordHelper t (t1 :*: t2) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

fromRecord' :: Record I t -> (t1 :*: t2) x Source #

(Key k t, Value k t ~ v) => FromRecordHelper t (S1 (MetaSel (Just k) unpackedness strictness laziness) (Rec0 v)) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

fromRecord' :: Record I t -> S1 (MetaSel (Just k) unpackedness strictness laziness) (Rec0 v) x Source #

FromRecordHelper t fields => FromRecordHelper t (D1 meta (C1 metacons fields)) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

fromRecord' :: Record I t -> D1 meta (C1 metacons fields) x Source #

type family VariantCode (s :: Type) :: RBT Symbol Type where ... Source #

Equations

VariantCode s = VariantCode' E (Rep s) 

type family VariantCode' (acc :: RBT Symbol Type) (g :: Type -> Type) :: RBT Symbol Type where ... Source #

Equations

VariantCode' acc (D1 meta fields) = VariantCode' acc fields 
VariantCode' acc (t1 :+: t2) = VariantCode' (VariantCode' acc t2) t1 
VariantCode' acc (C1 (MetaCons k _ _) (S1 (MetaSel Nothing unpackedness strictness laziness) (Rec0 v))) = Insert k v acc 

class FromVariant (s :: Type) where Source #

Minimal complete definition

Nothing

class FromVariantHelper (t :: RBT Symbol Type) (g :: Type -> Type) where Source #

Methods

fromVariant' :: Variant I t -> Maybe (g x) Source #

Instances
(FromVariantHelper t t1, FromVariantHelper t t2) => FromVariantHelper t (t1 :+: t2) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

fromVariant' :: Variant I t -> Maybe ((t1 :+: t2) x) Source #

(Key k t, Value k t ~ v) => FromVariantHelper t (C1 (MetaCons k x y) (S1 (MetaSel (Nothing :: Maybe Symbol) unpackedness strictness laziness) (Rec0 v))) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

fromVariant' :: Variant I t -> Maybe (C1 (MetaCons k x y) (S1 (MetaSel Nothing unpackedness strictness laziness) (Rec0 v)) x0) Source #

FromVariantHelper t fields => FromVariantHelper t (D1 meta fields) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

fromVariant' :: Variant I t -> Maybe (D1 meta fields x) Source #

class ToVariant (s :: Type) where Source #

Minimal complete definition

Nothing

class ToVariantHelper (t :: RBT Symbol Type) (g :: Type -> Type) where Source #

Methods

toVariant' :: g x -> Variant I t Source #

Instances
(ToVariantHelper t t1, ToVariantHelper t t2) => ToVariantHelper t (t1 :+: t2) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

toVariant' :: (t1 :+: t2) x -> Variant I t Source #

(Key k t, Value k t ~ v) => ToVariantHelper t (C1 (MetaCons k x y) (S1 (MetaSel (Nothing :: Maybe Symbol) unpackedness strictness laziness) (Rec0 v))) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

toVariant' :: C1 (MetaCons k x y) (S1 (MetaSel Nothing unpackedness strictness laziness) (Rec0 v)) x0 -> Variant I t Source #

ToVariantHelper t fields => ToVariantHelper t (D1 meta fields) Source # 
Instance details

Defined in Data.RBR.Internal

Methods

toVariant' :: D1 meta fields x -> Variant I t Source #