Ty#
- class discopy.monoidal.Ty(*inside)[source]#
Bases:
discopy.cat.Ob
A type is a tuple of objects with
Ty.tensor()
as concatenation.- Parameters:
inside (str | cat.Ob) – The objects inside the type (or their names).
Tip
Types can be instantiated with a name rather than object.
>>> assert Ty('x') == Ty(cat.Ob('x'))
Tip
A type can be exponentiated by a natural number.
>>> assert Ty('x') ** 3 == Ty('x', 'x', 'x')
Note
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
.inside
.>>> t = Ty(*"xyz") >>> assert t[0] == t[:1] == Ty('x') >>> assert t[0] != t.inside[0] == Ob('x') >>> assert t[1:] == t[-2:] == Ty('y', 'z')
- tensor(*others)[source]#
Returns the tensor of types, i.e. the concatenation of their lists of objects. This is called with the binary operator
@
.Tip
A list of types can be tensored by calling
Ty().tensor
.>>> list_of_types = [Ty('x'), Ty('y'), Ty('z')] >>> assert Ty().tensor(*list_of_types) == Ty('x', 'y', 'z')
- count(obj)[source]#
Counts the occurrence of a given object (or a type of length 1).
- Parameters:
obj (Ob) – The object to count.
- Return type:
int
Example
>>> x = Ty('x') >>> xs = x ** 5 >>> assert xs.count(x) == xs.inside.count(x.inside[0])
- property is_atomic: bool#
Whether a type is atomic, i.e. it has length 1.