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