Box#

class discopy.cat.Box(name, dom, cod, **params)[source]#

Bases: Arrow

Defines a box as an arrow with the list of only itself as boxes.

Parameters:
  • name (any) – Name of the box.

  • dom (cat.Ob) – Domain.

  • cod (cat.Ob) – Codomain.

  • data (any) – Extra data in the box, default is None.

Examples

>>> x, y = Ob('x'), Ob('y')
>>> f = Box('f', x, y, data=[42])
>>> assert f == Arrow(x, y, [f])
>>> assert f.boxes == [f]
>>> assert f[:0] == Id(f.dom) and f[1:] == Id(f.cod)
property name#

The name of a box is immutable.

>>> f = Box('f', Ob('x'), Ob('y'), data=[42, {0: 1}])
>>> assert f.name == 'f'
>>> f.name = 'g'  
Traceback (most recent call last):
...
AttributeError: can't set attribute...
property data#

The attribute data is immutable, but it can hold a mutable object.

>>> f = Box('f', Ob('x'), Ob('y'), data=[42, {0: 1}])
>>> assert f.data == [42, {0: 1}]
>>> f.data = [42, {0: 2}]  
Traceback (most recent call last):
...
AttributeError: can't set attribute...
>>> f.data[1][0] = 2
>>> assert f.data == [42, {0: 2}]
property is_dagger#

Whether the box is dagger.