- class discopy.monoidal.Ty(*inside)#
A type is a tuple of objects with
inside (str | cat.Ob) – The objects inside the type (or their names).
Types can be instantiated with a name rather than object.
>>> assert Ty('x') == Ty(cat.Ob('x'))
A type can be exponentiated by a natural number.
>>> assert Ty('x') ** 3 == Ty('x', 'x', 'x')
Types can be indexed and sliced using square brackets. Indexing behaves like that of strings, i.e. when we index a type we get a type back. The objects inside the type are still accessible using
>>> t = Ty(*"xyz") >>> assert t == t[:1] == Ty('x') >>> assert t != t.inside == Ob('x') >>> assert t[1:] == t[-2:] == Ty('y', 'z')
Returns the tensor of types, i.e. the concatenation of their lists of objects. This is called with the binary operator
A list of types can be tensored by calling
>>> list_of_types = [Ty('x'), Ty('y'), Ty('z')] >>> assert Ty().tensor(*list_of_types) == Ty('x', 'y', 'z')
Counts the occurrence of a given object (or a type of length 1).
obj (Ob) – The object to count.
- Return type:
>>> x = Ty('x') >>> xs = x ** 5 >>> assert xs.count(x) == xs.inside.count(x.inside)
- property is_atomic: bool#
Whether a type is atomic, i.e. it has length 1.