Idris2Doc : Data.SOP.NS

Data.SOP.NS

(source)

Definitions

dataNS_ : (k : Type) -> (k->Type) ->Listk->Type
  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.

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:

```idris example
the (NS_ Type I [Char,Bool]) (Z 'x')
the (NS_ Type I [Char,Bool]) (S $ Z False)
```

Totality: total
Visibility: public export
Constructors:
Z : ft->NS_kf (t::ks)
S : NS_kfks->NS_kf (t::ks)

Hints:
NP (DecEq.f) ks=>DecEq (NS_kfks)
NP (Eq.f) ks=>Eq (NS_kfks)
HApk (Listk) (NP_k) (NS_k)
HCollapsek (Listk) (NS_k) I
HFoldk (Listk) (NS_k)
HFunctork (Listk) (NS_k)
HSequencek (Listk) (NS_k)
NP (Monoid.f) [k'] =>Monoid (NS_kf [k'])
NP (Ord.f) ks=>Ord (NS_kfks)
NP (Semigroup.f) [k'] =>Semigroup (NS_kf [k'])
NP (Show.f) ks=>Show (NS_kfks)
Uninhabited (Zx=Sy)
Uninhabited (Sx=Zy)
NS : (k->Type) ->Listk->Type
  Type alias for `NS_` with type parameter `k` being
implicit. This reflects the kind-polymorphic data type
in Haskell.

Totality: total
Visibility: public export
toI : NS_kfks->NSI (mapfks)
  Changes an n-ary sum to the identity context `I`
by adjusting the types of stored values accordingly.

Totality: total
Visibility: public export
mapNS : (fa->ga) ->NSfks->NSgks
  Specialiced version of `hmap`

Totality: total
Visibility: public export
foldlNS : (acc->el->acc) ->acc->NS (Kel) ks->acc
  Specialization of `hfoldl`

Totality: total
Visibility: public export
foldrNS : (el-> Lazy acc->acc) -> Lazy acc->NS (Kel) ks->acc
  Specialization of `hfoldr`

Totality: total
Visibility: public export
sequenceNS : Applicativeg=>NS (\a=>g (fa)) ks->g (NSfks)
  Specialization of `hsequence`

Totality: total
Visibility: public export
hapNS : NP (\a=>fa->ga) ks->NSfks->NSgks
  Specialization of `hap`

Totality: total
Visibility: public export
collapseNS : NS (Ka) ks->a
  Specialization of `hcollapse`

Totality: total
Visibility: public export
0Injection : (k->Type) ->Listk->k->Type
  An injection into an n-ary sum takes a value of the correct
type and wraps it in one of the sum's possible choices.

Totality: total
Visibility: public export
injectionsNP : NPgks->NP (Injectionfks) ks
  The set of injections into an n-ary sum `NS f ks` can
be wrapped in a corresponding n-ary product.

Totality: total
Visibility: public export
injections : NP (Injectionfks) ks
  The set of injections into an n-ary sum `NS f ks` can
be wrapped in a corresponding n-ary product.

Totality: total
Visibility: public export
apInjsNP_ : NPfks->NP (K (NSfks)) ks
  Applies all injections to an n-ary product of values.

This is not implemented in terms of injections for the
following reason: Since we have access to the structure
of the n-ary product and thus `ks`, we do not need a
runtime reference of `ks`. Therefore, when applying
injections to an n-ary product, prefer this function
over a combination involving `injections`.

Totality: total
Visibility: public export
apInjsNP : NPfks->List (NSfks)
  Alias for `collapseNP . apInjsNP_`

Totality: total
Visibility: public export
inject : ft->Elemtks=>NSfks
  Injects a value into an n-ary sum.

Totality: total
Visibility: public export
extract : (0t : k) ->NSfks->Elemtks=>Maybe (ft)
  Tries to extract a value of the given type from an n-ary sum.

Totality: total
Visibility: public export
toNP : Alternativeg=>NSfks->NP (g.f) ks
  Converts an n-ary sum into the corresponding n-ary product
of alternatives.

Totality: total
Visibility: public export
expand : NSfks->Sublistksks'=>NSfks'
  Injects an n-ary sum into a larger n-ary sum.

Totality: total
Visibility: public export
narrow : NSfks->Sublistks'ks=>Maybe (NSfks')
  Tries to narrow down an n-ary sum to a subset of
choices. `ks'` must be a sublist (values in the same order) of `ks`.

Totality: total
Visibility: public export