Safe Haskell | None |
---|---|
Language | Haskell2010 |
Synopsis
- data Color
- data RBT k v
- class KeysValuesAllF c t => KeysValuesAll (c :: k -> v -> Constraint) (t :: RBT k v)
- class KnownSymbol k => KnownKey (k :: Symbol) (v :: z)
- demoteKeys :: forall t. KeysValuesAll KnownKey t => Record (K String) t
- data Record (f :: Type -> Type) (t :: RBT Symbol Type)
- unit :: Record f E
- 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
- prettyShowRecordI :: forall t flat. (KeysValuesAll KnownKey t, Productlike '[] t flat, All Show flat, SListI flat) => Record I t -> String
- data Variant (f :: Type -> Type) (t :: RBT Symbol Type)
- impossible :: Variant f E -> b
- 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
- prettyShowVariantI :: forall t flat. (KeysValuesAll KnownKey t, Productlike '[] t flat, Sumlike '[] t flat, All Show flat, SListI flat) => Variant I t -> String
- class Insertable (k :: Symbol) (v :: Type) (t :: RBT Symbol Type) where
- addField :: forall k v t f. Insertable k v t => f v -> Record f t -> Record f (Insert k v t)
- insertI :: forall k v t. Insertable k v t => v -> Record I t -> Record I (Insert k v t)
- addFieldI :: forall k v t. Insertable k v t => v -> Record I t -> Record I (Insert k v t)
- type family InsertAll (es :: [(Symbol, Type)]) (t :: RBT Symbol Type) :: RBT Symbol Type where ...
- type FromList (es :: [(Symbol, Type)]) = InsertAll es E
- class Key (k :: Symbol) (t :: RBT Symbol Type) where
- project :: forall k t f. Key k t => Record f t -> f (Value k t)
- projectI :: forall k t. Key k t => Record I t -> Value k t
- getField :: forall k t f. Key k t => Record f t -> f (Value k t)
- getFieldI :: forall k t. Key k t => Record I t -> Value k t
- setField :: forall k t f. Key k t => f (Value k t) -> Record f t -> Record f t
- setFieldI :: forall k t. Key k t => Value k t -> Record I t -> Record I t
- modifyField :: forall k t f. Key k t => (f (Value k t) -> f (Value k t)) -> Record f t -> Record f t
- modifyFieldI :: forall k t. Key k t => (Value k t -> Value k t) -> Record I t -> Record I t
- inject :: forall k t f. Key k t => f (Value k t) -> Variant f t
- injectI :: forall k t. Key k t => Value k t -> Variant I t
- match :: forall k t f. Key k t => Variant f t -> Maybe (f (Value k t))
- matchI :: forall k t. Key k t => Variant I t -> Maybe (Value k t)
- eliminate :: (Productlike '[] t result, Sumlike '[] t result, SListI result) => Record (Case f r) t -> Variant f t -> r
- newtype Case f a b = 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)
- 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)
- class (Key k t, Value k t ~ v) => PresentIn (t :: RBT Symbol Type) (k :: Symbol) (v :: Type)
- type ProductlikeSubset (subset :: RBT Symbol Type) (whole :: RBT Symbol Type) (flat :: [Type]) = (KeysValuesAll (PresentIn whole) subset, Productlike '[] subset flat, SListI flat)
- fieldSubset :: forall subset whole flat f. ProductlikeSubset subset whole flat => Record f whole -> (Record f subset -> Record f whole, Record f subset)
- projectSubset :: forall subset whole flat f. ProductlikeSubset subset whole flat => Record f whole -> Record f subset
- getFieldSubset :: forall subset whole flat f. ProductlikeSubset subset whole flat => Record f whole -> Record f subset
- setFieldSubset :: forall subset whole flat f. ProductlikeSubset subset whole flat => Record f subset -> Record f whole -> Record f whole
- modifyFieldSubset :: forall subset whole flat f. ProductlikeSubset subset whole flat => (Record f subset -> Record f subset) -> Record f whole -> Record f whole
- 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)
- 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)
- injectSubset :: forall subset whole subflat wholeflat f. SumlikeSubset subset whole subflat wholeflat => Variant f subset -> Variant f whole
- matchSubset :: forall subset whole subflat wholeflat f. SumlikeSubset subset whole subflat wholeflat => Variant f whole -> Maybe (Variant f subset)
- eliminateSubset :: forall subset whole subflat wholeflat f r. SumlikeSubset subset whole subflat wholeflat => Record (Case f r) whole -> Variant f subset -> r
- class ToRecord (r :: Type) where
- type RecordCode r :: RBT Symbol Type
- toRecord :: r -> Record I (RecordCode r)
- class ToRecord r => FromRecord (r :: Type) where
- fromRecord :: Record I (RecordCode r) -> r
- type family VariantCode (s :: Type) :: RBT Symbol Type where ...
- class ToVariant (s :: Type) where
- toVariant :: s -> Variant I (VariantCode s)
- class FromVariant (s :: Type) where
- fromVariant :: Variant I (VariantCode s) -> s
- class Productlike (start :: [Type]) (t :: RBT Symbol Type) (result :: [Type]) | start t -> result, result t -> start where
- fromNP :: forall t result f. Productlike '[] t result => NP f result -> Record f t
- toNP :: forall t result f. Productlike '[] t result => Record f t -> NP f result
- class Sumlike (start :: [Type]) (t :: RBT Symbol Type) (result :: [Type]) | start t -> result, result t -> start where
- fromNS :: forall t result f. Sumlike '[] t result => NS f result -> Variant f t
- toNS :: forall t result f. Sumlike '[] t result => Variant f t -> NS f result
- newtype I a = I a
- newtype K a (b :: k) :: forall k. Type -> k -> Type = K a
- data NP (a :: k -> Type) (b :: [k]) :: forall k. (k -> Type) -> [k] -> Type where
- data NS (a :: k -> Type) (b :: [k]) :: forall k. (k -> Type) -> [k] -> Type where
Type-level Red-Black tree
A Red-Black tree that is used at the type level, with DataKinds
. The tree
keeps track of what keys are present and to what types they correspond.
The color of a node.
class KeysValuesAllF c t => KeysValuesAll (c :: k -> v -> Constraint) (t :: RBT k v) 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.
Instances
KeysValuesAll (c :: k -> v -> Constraint) (E :: RBT k v) Source # | |
Defined in Data.RBR.Internal | |
(c k2 v2, KeysValuesAll c left, KeysValuesAll c right) => KeysValuesAll (c :: k1 -> v1 -> Constraint) (N color left k2 v2 right :: RBT k1 v1) Source # | |
Defined in Data.RBR.Internal |
class KnownSymbol k => KnownKey (k :: Symbol) (v :: z) Source #
Instances
KnownSymbol k => KnownKey k (v :: z) Source # | |
Defined in Data.RBR.Internal |
demoteKeys :: forall t. KeysValuesAll KnownKey t => Record (K String) t Source #
Records and Variants
data Record (f :: Type -> Type) (t :: RBT Symbol Type) Source #
A Record without components is a boring, uninformative type whose single value can be conjured out of thin air.
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 #
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.
data Variant (f :: Type -> Type) (t :: RBT Symbol Type) Source #
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 #
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.
Inserting and widening
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.
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
.
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.
type FromList (es :: [(Symbol, Type)]) = InsertAll es E Source #
Build a type-level tree out of a list of type level key / value pairs.
Projecting and injecting
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.
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 (N color left k' v' right)) => Key k (N color left k' v' right) Source # | |
Defined in Data.RBR.Internal 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 # |
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
.
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
.
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 Record
s.
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.
matchI :: forall k t. Key k t => Variant I t -> Maybe (Value k t) Source #
Like match
but specialized to pure Variants
s.
Eliminating variants
eliminate :: (Productlike '[] t result, Sumlike '[] t result, SListI result) => Record (Case f r) t -> Variant f t -> r Source #
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 #
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
.
Subsets of fields and branches
class (Key k t, Value k t ~ v) => PresentIn (t :: RBT Symbol Type) (k :: Symbol) (v :: Type) Source #
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 #
Interfacing with normal records
Typeclasses for converting to and from normal Haskell records and sum types.
They have default implementations based in GHC.Generics:
>>>
data Person = Person { name :: String, age :: Int } deriving (Generic, Show)
>>>
instance ToRecord Person
>>>
instance FromRecord Person
>>>
data Summy = Lefty Int | Righty Bool deriving (Generic,Show)
>>>
instance ToVariant Summy
>>>
instance FromVariant Summy
Only single-constructor records with named fields can have ToRecord
and
FromRecord
instances.
Only sum types with exactly one anonymous argument on each branch can have
ToVariant
and FromVariant
instances.
class ToRecord (r :: Type) where Source #
Nothing
toRecord :: r -> Record I (RecordCode r) Source #
toRecord :: (Generic r, ToRecordHelper E (Rep r), RecordCode r ~ RecordCode' E (Rep r)) => r -> Record I (RecordCode r) Source #
class ToRecord r => FromRecord (r :: Type) where Source #
Nothing
fromRecord :: Record I (RecordCode r) -> r Source #
fromRecord :: (Generic r, FromRecordHelper (RecordCode r) (Rep r)) => Record I (RecordCode r) -> r Source #
type family VariantCode (s :: Type) :: RBT Symbol Type where ... Source #
VariantCode s = VariantCode' E (Rep s) |
class ToVariant (s :: Type) where Source #
Nothing
toVariant :: s -> Variant I (VariantCode s) Source #
toVariant :: (Generic s, ToVariantHelper (VariantCode s) (Rep s)) => s -> Variant I (VariantCode s) Source #
class FromVariant (s :: Type) where Source #
Nothing
fromVariant :: Variant I (VariantCode s) -> s Source #
fromVariant :: (Generic s, FromVariantHelper (VariantCode s) (Rep s)) => Variant I (VariantCode s) -> s Source #
Interfacing with Data.SOP
class Productlike (start :: [Type]) (t :: RBT Symbol Type) (result :: [Type]) | start t -> result, result t -> start where Source #
Class from converting Record
s 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.
Instances
Productlike start (E :: RBT Symbol Type) start Source # | |
(Productlike start right middle, Productlike (v ': middle) left result) => Productlike start (N color left k v right) result Source # | |
fromNP :: forall t result f. Productlike '[] t result => NP f result -> Record f t Source #
Convert a n-ary product into a compatible Record
.
toNP :: forall t result f. Productlike '[] t result => Record f t -> NP f result Source #
Convert a Record
into a n-ary product.
class Sumlike (start :: [Type]) (t :: RBT Symbol Type) (result :: [Type]) | start t -> result, result t -> start where Source #
Class from converting Variant
s 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.
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 # | |
(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 # | |
Defined in Data.RBR.Internal | |
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 # | |
Sumlike start (N color (E :: RBT Symbol Type) k v (E :: RBT Symbol Type)) (v ': start) Source # | |
fromNS :: forall t result f. Sumlike '[] t result => NS f result -> Variant f t Source #
Convert a n-ary sum into a compatible Variant
.
toNS :: forall t result f. Sumlike '[] t result => Variant f t -> NS f result Source #
Convert a Variant
into a n-ary sum.
Data.SOP re-exports
The identity type functor.
Like Identity
, but with a shorter name.
I a |
Instances
Monad I | |
Functor I | |
Applicative I | |
Foldable I | |
Defined in Data.SOP.BasicFunctors fold :: Monoid m => I m -> m # foldMap :: Monoid m => (a -> m) -> I a -> m # foldr :: (a -> b -> b) -> b -> I a -> b # foldr' :: (a -> b -> b) -> b -> I a -> b # foldl :: (b -> a -> b) -> b -> I a -> b # foldl' :: (b -> a -> b) -> b -> I a -> b # foldr1 :: (a -> a -> a) -> I a -> a # foldl1 :: (a -> a -> a) -> I a -> a # elem :: Eq a => a -> I a -> Bool # maximum :: Ord a => I a -> a # | |
Traversable I | |
Eq1 I | Since: sop-core-0.2.4.0 |
Ord1 I | Since: sop-core-0.2.4.0 |
Defined in Data.SOP.BasicFunctors | |
Read1 I | Since: sop-core-0.2.4.0 |
Show1 I | Since: sop-core-0.2.4.0 |
NFData1 I | Since: sop-core-0.2.5.0 |
Defined in Data.SOP.BasicFunctors | |
Eq a => Eq (I a) | |
Ord a => Ord (I a) | |
Read a => Read (I a) | |
Show a => Show (I a) | |
Generic (I a) | |
Semigroup a => Semigroup (I a) | Since: sop-core-0.4.0.0 |
Monoid a => Monoid (I a) | Since: sop-core-0.4.0.0 |
NFData a => NFData (I a) | Since: sop-core-0.2.5.0 |
Defined in Data.SOP.BasicFunctors | |
type Rep (I a) | |
Defined in Data.SOP.BasicFunctors |
newtype K a (b :: k) :: forall k. Type -> k -> Type #
The constant type functor.
Like Constant
, but kind-polymorphic
in its second argument and with a shorter name.
K a |
Instances
Eq2 (K :: Type -> Type -> Type) | Since: sop-core-0.2.4.0 |
Ord2 (K :: Type -> Type -> Type) | Since: sop-core-0.2.4.0 |
Defined in Data.SOP.BasicFunctors | |
Read2 (K :: Type -> Type -> Type) | Since: sop-core-0.2.4.0 |
Defined in Data.SOP.BasicFunctors liftReadsPrec2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> Int -> ReadS (K a b) # liftReadList2 :: (Int -> ReadS a) -> ReadS [a] -> (Int -> ReadS b) -> ReadS [b] -> ReadS [K a b] # liftReadPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec (K a b) # liftReadListPrec2 :: ReadPrec a -> ReadPrec [a] -> ReadPrec b -> ReadPrec [b] -> ReadPrec [K a b] # | |
Show2 (K :: Type -> Type -> Type) | Since: sop-core-0.2.4.0 |
NFData2 (K :: Type -> Type -> Type) | Since: sop-core-0.2.5.0 |
Defined in Data.SOP.BasicFunctors | |
Functor (K a :: Type -> Type) | |
Monoid a => Applicative (K a :: Type -> Type) | |
Foldable (K a :: Type -> Type) | |
Defined in Data.SOP.BasicFunctors fold :: Monoid m => K a m -> m # foldMap :: Monoid m => (a0 -> m) -> K a a0 -> m # foldr :: (a0 -> b -> b) -> b -> K a a0 -> b # foldr' :: (a0 -> b -> b) -> b -> K a a0 -> b # foldl :: (b -> a0 -> b) -> b -> K a a0 -> b # foldl' :: (b -> a0 -> b) -> b -> K a a0 -> b # foldr1 :: (a0 -> a0 -> a0) -> K a a0 -> a0 # foldl1 :: (a0 -> a0 -> a0) -> K a a0 -> a0 # elem :: Eq a0 => a0 -> K a a0 -> Bool # maximum :: Ord a0 => K a a0 -> a0 # minimum :: Ord a0 => K a a0 -> a0 # | |
Traversable (K a :: Type -> Type) | |
Eq a => Eq1 (K a :: Type -> Type) | Since: sop-core-0.2.4.0 |
Ord a => Ord1 (K a :: Type -> Type) | Since: sop-core-0.2.4.0 |
Defined in Data.SOP.BasicFunctors | |
Read a => Read1 (K a :: Type -> Type) | Since: sop-core-0.2.4.0 |
Defined in Data.SOP.BasicFunctors | |
Show a => Show1 (K a :: Type -> Type) | Since: sop-core-0.2.4.0 |
NFData a => NFData1 (K a :: Type -> Type) | Since: sop-core-0.2.5.0 |
Defined in Data.SOP.BasicFunctors | |
Eq a => Eq (K a b) | |
Ord a => Ord (K a b) | |
Read a => Read (K a b) | |
Show a => Show (K a b) | |
Generic (K a b) | |
Semigroup a => Semigroup (K a b) | Since: sop-core-0.4.0.0 |
Monoid a => Monoid (K a b) | Since: sop-core-0.4.0.0 |
NFData a => NFData (K a b) | Since: sop-core-0.2.5.0 |
Defined in Data.SOP.BasicFunctors | |
type Rep (K a b) | |
Defined in Data.SOP.BasicFunctors |
data NP (a :: k -> Type) (b :: [k]) :: forall k. (k -> Type) -> [k] -> Type where #
An n-ary product.
The product is parameterized by a type constructor f
and
indexed by a type-level list xs
. The length of the list
determines the number of elements in the product, and if the
i
-th element of the list is of type x
, then the i
-th
element of the product is of type f x
.
The constructor names are chosen to resemble the names of the list constructors.
Two common instantiations of f
are the identity functor I
and the constant functor K
. For I
, the product becomes a
heterogeneous list, where the type-level list describes the
types of its components. For
, the product becomes a
homogeneous list, where the contents of the type-level list are
ignored, but its length still specifies the number of elements.K
a
In the context of the SOP approach to generic programming, an n-ary product describes the structure of the arguments of a single data constructor.
Examples:
I 'x' :* I True :* Nil :: NP I '[ Char, Bool ] K 0 :* K 1 :* Nil :: NP (K Int) '[ Char, Bool ] Just 'x' :* Nothing :* Nil :: NP Maybe '[ Char, Bool ]
Nil :: forall k (a :: k -> Type) (b :: [k]). NP a ([] :: [k]) | |
(:*) :: forall k (a :: k -> Type) (b :: [k]) (x :: k) (xs :: [k]). a x -> NP a xs -> NP a (x ': xs) infixr 5 |
Instances
HTrans (NP :: (k1 -> Type) -> [k1] -> Type) (NP :: (k2 -> Type) -> [k2] -> Type) | |
HPure (NP :: (k -> Type) -> [k] -> Type) | |
HAp (NP :: (k -> Type) -> [k] -> Type) | |
HCollapse (NP :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NP | |
HTraverse_ (NP :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NP hctraverse_ :: (AllN NP c xs, Applicative g) => proxy c -> (forall (a :: k0). c a => f a -> g ()) -> NP f xs -> g () # htraverse_ :: (SListIN NP xs, Applicative g) => (forall (a :: k0). f a -> g ()) -> NP f xs -> g () # | |
HSequence (NP :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NP hsequence' :: (SListIN NP xs, Applicative f) => NP (f :.: g) xs -> f (NP g xs) # hctraverse' :: (AllN NP c xs, Applicative g) => proxy c -> (forall (a :: k0). c a => f a -> g (f' a)) -> NP f xs -> g (NP f' xs) # htraverse' :: (SListIN NP xs, Applicative g) => (forall (a :: k0). f a -> g (f' a)) -> NP f xs -> g (NP f' xs) # | |
All (Compose Eq f) xs => Eq (NP f xs) | |
(All (Compose Eq f) xs, All (Compose Ord f) xs) => Ord (NP f xs) | |
All (Compose Show f) xs => Show (NP f xs) | |
All (Compose Semigroup f) xs => Semigroup (NP f xs) | Since: sop-core-0.4.0.0 |
(All (Compose Monoid f) xs, All (Compose Semigroup f) xs) => Monoid (NP f xs) | Since: sop-core-0.4.0.0 |
All (Compose NFData f) xs => NFData (NP f xs) | Since: sop-core-0.2.5.0 |
Defined in Data.SOP.NP | |
type Same (NP :: (k1 -> Type) -> [k1] -> Type) | |
type Prod (NP :: (k -> Type) -> [k] -> Type) | |
type UnProd (NP :: (k -> Type) -> [k] -> Type) | |
type CollapseTo (NP :: (k -> Type) -> [k] -> Type) a | |
Defined in Data.SOP.NP | |
type SListIN (NP :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NP | |
type AllN (NP :: (k -> Type) -> [k] -> Type) (c :: k -> Constraint) | |
Defined in Data.SOP.NP | |
type AllZipN (NP :: (k -> Type) -> [k] -> Type) (c :: a -> b -> Constraint) | |
Defined in Data.SOP.NP |
data NS (a :: k -> Type) (b :: [k]) :: forall k. (k -> Type) -> [k] -> Type where #
An n-ary sum.
The sum is parameterized by a type constructor f
and
indexed by a type-level list xs
. The length of the list
determines the number of choices in the sum and if the
i
-th element of the list is of type x
, then the i
-th
choice of the sum is of type f x
.
The constructor names are chosen to resemble Peano-style
natural numbers, i.e., Z
is for "zero", and S
is for
"successor". Chaining S
and Z
chooses the corresponding
component of the sum.
Examples:
Z :: f x -> NS f (x ': xs) S . Z :: f y -> NS f (x ': y ': xs) S . S . Z :: f z -> NS f (x ': y ': z ': xs) ...
Note that empty sums (indexed by an empty list) have no non-bottom elements.
Two common instantiations of f
are the identity functor I
and the constant functor K
. For I
, the sum becomes a
direct generalization of the Either
type to arbitrarily many
choices. For
, the result is a homogeneous choice type,
where the contents of the type-level list are ignored, but its
length specifies the number of options.K
a
In the context of the SOP approach to generic programming, an n-ary sum describes the top-level structure of a datatype, which is a choice between all of its constructors.
Examples:
Z (I 'x') :: NS I '[ Char, Bool ] S (Z (I True)) :: NS I '[ Char, Bool ] S (Z (K 1)) :: NS (K Int) '[ Char, Bool ]
Z :: forall k (a :: k -> Type) (b :: [k]) (x :: k) (xs :: [k]). a x -> NS a (x ': xs) | |
S :: forall k (a :: k -> Type) (b :: [k]) (xs :: [k]) (x :: k). NS a xs -> NS a (x ': xs) |
Instances
HTrans (NS :: (k1 -> Type) -> [k1] -> Type) (NS :: (k2 -> Type) -> [k2] -> Type) | |
HAp (NS :: (k -> Type) -> [k] -> Type) | |
HCollapse (NS :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NS | |
HTraverse_ (NS :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NS hctraverse_ :: (AllN NS c xs, Applicative g) => proxy c -> (forall (a :: k0). c a => f a -> g ()) -> NS f xs -> g () # htraverse_ :: (SListIN NS xs, Applicative g) => (forall (a :: k0). f a -> g ()) -> NS f xs -> g () # | |
HSequence (NS :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NS hsequence' :: (SListIN NS xs, Applicative f) => NS (f :.: g) xs -> f (NS g xs) # hctraverse' :: (AllN NS c xs, Applicative g) => proxy c -> (forall (a :: k0). c a => f a -> g (f' a)) -> NS f xs -> g (NS f' xs) # htraverse' :: (SListIN NS xs, Applicative g) => (forall (a :: k0). f a -> g (f' a)) -> NS f xs -> g (NS f' xs) # | |
HIndex (NS :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NS | |
HApInjs (NS :: (k -> Type) -> [k] -> Type) | |
HExpand (NS :: (k -> Type) -> [k] -> Type) | |
All (Compose Eq f) xs => Eq (NS f xs) | |
(All (Compose Eq f) xs, All (Compose Ord f) xs) => Ord (NS f xs) | |
All (Compose Show f) xs => Show (NS f xs) | |
All (Compose NFData f) xs => NFData (NS f xs) | Since: sop-core-0.2.5.0 |
Defined in Data.SOP.NS | |
type Same (NS :: (k1 -> Type) -> [k1] -> Type) | |
type Prod (NS :: (k -> Type) -> [k] -> Type) | |
type CollapseTo (NS :: (k -> Type) -> [k] -> Type) a | |
Defined in Data.SOP.NS | |
type SListIN (NS :: (k -> Type) -> [k] -> Type) | |
Defined in Data.SOP.NS | |
type AllN (NS :: (k -> Type) -> [k] -> Type) (c :: k -> Constraint) | |
Defined in Data.SOP.NS |