Anamorphism for NS.
Modulegenerics-sop-0.5.1.4Haskell2010
Generics.SOP.NS
- 4 types
- 66 values
- Packagegenerics-sop-0.5.1.4
- Exports70
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceNS.hs
apInjs_POP without hcollapse.
Example:
apInjs'_POP (POP ((I 'x' :* Nil) :* (I True :* I 2 :* Nil) :* Nil))K (SOP (Z (I 'x' :* Nil))) :* K (SOP (S (Z (I True :* I 2 :* Nil)))) :* Nil
Apply injections to a product.
Given a product containing all possible choices, produce a list of sums by applying each injection to the appropriate element.
Example:
apInjs_NP (I 'x' :* I True :* I 2 :* Nil)[Z (I 'x'),S (Z (I True)),S (S (Z (I 2)))]
Apply injections to a product of product.
This operates on the outer product only. Given a product containing all possible choices (that are products), produce a list of sums (of products) by applying each injection to the appropriate element.
Example:
apInjs_POP (POP ((I 'x' :* Nil) :* (I True :* I 2 :* Nil) :* Nil))[SOP (Z (I 'x' :* Nil)),SOP (S (Z (I True :* I 2 :* Nil)))]
Specialization of hap.
Specialization of hap.
Constrained anamorphism for NS.
Constrained catamorphism for NS.
ccompare_NS Constrained version of compare_NS.
ccompare_SOP Constrained version of compare_SOP.
Specialization of hcexpand.
Specialization of hcexpand.
Specialization of hcfoldMap.
Deprecated. Use cliftA2_NS instead.
Specialization of hcliftA2'.
Specialization of hcliftA2.
Specialization of hcliftA2.
Specialization of hcliftA.
Specialization of hcliftA.
Specialization of hcoerce.
Specialization of hcoerce.
Specialization of hcollapse.
Specialization of hcollapse.
compare_NS Compare two sums with respect to the choice they are making.
A value that chooses the first option is considered smaller than one that chooses the second option.
If the choices are different, then either the first (if the first is smaller than the second) or the third (if the first is larger than the second) argument are called. If both choices are equal, then the second argument is called, which has access to the elements contained in the sums.
compare_SOP Compare two sums of products with respect to the choice in the sum they are making.
Only the sum structure is used for comparison. This is a small wrapper around ccompare_NS for a common special case.
Specialization of hctraverse'.
Note: as NS has exactly one element, the Functor constraint is enough.
Specialization of hctraverse'.
Specialization of hctraverse.
Specialization of hctraverse.
Specialization of hctraverse_.
Note: we don't need Applicative constraint.
Specialization of hctraverse_.
Compute all ejections from an n-ary sum.
Each element of the resulting product contains one of the ejections.
Specialization of hexpand.
Specialization of hexpand.
Specialization of hfromI.
Specialization of hfromI.
Obtain the index from an n-ary sum.
An n-nary sum represents a choice between n different options. This function returns an integer between 0 and n - 1 indicating the option chosen by the given value.
Examples:
index_NS (S (S (Z (I False))))2index_NS (Z (K ()))0
Obtain the index from an n-ary sum of products.
An n-nary sum represents a choice between n different options. This function returns an integer between 0 and n - 1 indicating the option chosen by the given value.
Specification:
index_SOP = index_NS . unSOP
Example:
index_SOP (SOP (S (Z (I True :* I 'x' :* Nil))))1
Compute all injections into an n-ary sum.
Each element of the resulting product contains one of the injections.
Specialization of hliftA2.
Specialization of hliftA2.
Specialization of hliftA.
Specialization of hliftA.
Specialization of hsequence'.
Specialization of hsequence'.
Specialization of hsequence.
Specialization of hsequence.
Deprecated. Use shiftInjection instead.
Shift an injection.
Given an injection, return an injection into a sum that is one component larger.
Shift an injection.
Given an injection, return an injection into a sum that is one component larger.
Specialization of htoI.
Specialization of htoI.
Specialization of htrans.
Specialization of htrans.
Specialization of htraverse'.
Note: as NS has exactly one element, the Functor constraint is enough.
Specialization of htraverse'.
Specialization of htraverse_.
Note: we don't need Applicative constraint.
Specialization of htraverse_.
Unwrap a sum of products.
Extract the payload from a unary sum.
For larger sums, this function would be partial, so it is only provided with a rather restrictive type.
Example:
unZ (Z (I 'x'))I 'x'
The type of ejections from an n-ary sum.
An ejection is the pattern matching function for one part of the n-ary sum.
It is the opposite of an Injection.
The type of injections into an n-ary sum.
If you expand the type synonyms and newtypes involved, you get
Injection f xs a = (f -.-> K (NS f xs)) a ~= f a -> K (NS f xs) a ~= f a -> NS f xsIf we pick a to be an element of xs, this indeed corresponds to an
injection into the sum.
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 K a, 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.
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 ]Instances17HTrans, HAp, HApInjs, HCollapse, HExpand, HIndex, …
HTrans NS NSDefined in sop-core-0.5.0.2 · Data.SOP.NSHAp NSDefined in sop-core-0.5.0.2 · Data.SOP.NSHApInjs NSDefined in sop-core-0.5.0.2 · Data.SOP.NSHCollapse NSDefined in sop-core-0.5.0.2 · Data.SOP.NSHExpand NSDefined in sop-core-0.5.0.2 · Data.SOP.NSHIndex NSDefined in sop-core-0.5.0.2 · Data.SOP.NSHSequence NSDefined in sop-core-0.5.0.2 · Data.SOP.NSHTraverse_ NSDefined in sop-core-0.5.0.2 · Data.SOP.NSAll (Compose Eq f) xs => Eq (NS f xs)Defined in sop-core-0.5.0.2 · Data.SOP.NS(All (Compose Eq f) xs, All (Compose Ord f) xs) => Ord (NS f xs)Defined in sop-core-0.5.0.2 · Data.SOP.NSAll (Compose Show f) xs => Show (NS f xs)Defined in sop-core-0.5.0.2 · Data.SOP.NSAll (Compose NFData f) xs => NFData (NS f xs)Defined in sop-core-0.5.0.2 · Data.SOP.NStype CollapseTo NS a = aDefined in sop-core-0.5.0.2 · Data.SOP.NStype Prod NS = NPDefined in sop-core-0.5.0.2 · Data.SOP.NStype AllN NS c = All cDefined in sop-core-0.5.0.2 · Data.SOP.NStype Same NS = NSDefined in sop-core-0.5.0.2 · Data.SOP.NStype SListIN NS = SListIDefined in sop-core-0.5.0.2 · Data.SOP.NS
A sum of products.
This is a newtype for an NS of an NP. The elements of the
(inner) products are applications of the parameter f. The type
SOP is indexed by the list of lists that determines the sizes
of both the (outer) sum and all the (inner) products, as well as
the types of all the elements of the inner products.
A SOP I reflects the structure of a normal Haskell datatype.
The sum structure represents the choice between the different
constructors, the product structure represents the arguments of
each constructor.
Instances17HTrans, HAp, HApInjs, HCollapse, HExpand, HIndex, …
HTrans SOP SOPDefined in sop-core-0.5.0.2 · Data.SOP.NSHAp SOPDefined in sop-core-0.5.0.2 · Data.SOP.NSHApInjs SOPDefined in sop-core-0.5.0.2 · Data.SOP.NSHCollapse SOPDefined in sop-core-0.5.0.2 · Data.SOP.NSHExpand SOPDefined in sop-core-0.5.0.2 · Data.SOP.NSHIndex SOPDefined in sop-core-0.5.0.2 · Data.SOP.NSHSequence SOPDefined in sop-core-0.5.0.2 · Data.SOP.NSHTraverse_ SOPDefined in sop-core-0.5.0.2 · Data.SOP.NSEq (NS (NP f) xss) => Eq (SOP f xss)Defined in sop-core-0.5.0.2 · Data.SOP.NSOrd (NS (NP f) xss) => Ord (SOP f xss)Defined in sop-core-0.5.0.2 · Data.SOP.NSShow (NS (NP f) xss) => Show (SOP f xss)Defined in sop-core-0.5.0.2 · Data.SOP.NSNFData (NS (NP f) xss) => NFData (SOP f xss)Defined in sop-core-0.5.0.2 · Data.SOP.NStype CollapseTo SOP a = [a]Defined in sop-core-0.5.0.2 · Data.SOP.NStype Prod SOP = POPDefined in sop-core-0.5.0.2 · Data.SOP.NStype AllN SOP c = All2 cDefined in sop-core-0.5.0.2 · Data.SOP.NStype Same SOP = SOPDefined in sop-core-0.5.0.2 · Data.SOP.NStype SListIN SOP = SListI2Defined in sop-core-0.5.0.2 · Data.SOP.NS