List

Contents

List#

class discopy.monoidal.List(*inside)[source]#

Bases: discopy.abc.Monoid, discopy.utils.Result

The free monoid on a generator_factory, i.e. lists of its instances with concatenation as tensor() and the empty list as unit.

List[X] is the free monoid on X the way Hypergraph[C] is the hypergraph category over a category C, e.g. python.Function.ob is List[type], the free monoid on Python’s type. It has a single, trivial colour: Ty is the free coloured monoid, with Colour boundaries on its Wire generators, and Nat the free monoid on a single generator.

>>> assert List[int](2, 3) @ List[int](4) == List[int](2, 3, 4)
>>> assert List[int](2, 3) ** 2 == List[int](2, 3, 2, 3)
>>> assert List[int](2, 3)[1:] == List[int](3) and not List[int]()

Note

A list is a sequence of its length-one sublists, e.g. List[int](2, 3)[0] == List[int](2); the atoms themselves are its inside, e.g. List[int](2, 3).inside[0] == 2.