Ty#

class discopy.stream.Ty(now=None, _later=None)[source]#

Bases: NamedGeneric['base']

A stream of types from some underlying class base.

Parameters:
  • now (base) – The value of the stream at time step zero.

  • _later (Optional[Callable[[], Ty[base]]]) – A thunk for the tail of the stream, constant by default.

base#

alias of Ty

factory#

alias of Ty

property later: Ty#

The tail of a stream, or self if is_constant().

property head: Ty#

The singleton() over the first time step.

property tail: Ty#

The tail of a stream, or self if is_constant().

property is_constant: bool#

Whether a stream of type is constant.

classmethod singleton(x)[source]#

Constructs the stream with x now and the empty stream later.

>>> XY = Ty.singleton(symmetric.Ty('x', 'y'))
>>> for x in [XY.now, XY.later.now, XY.later.later.now]: print(x)
x @ y
Ty()
Ty()
Parameters:

x (base) –

Return type:

Ty

delay()[source]#

Delays a stream of types by pre-pending with the unit.

>>> XY = Ty(symmetric.Ty('x', 'y')).delay()
>>> for x in [XY.now, XY.later.now, XY.later.later.now]: print(x)
Ty()
x @ y
x @ y
Return type:

Ty

classmethod sequence(x, n_steps=0)[source]#

Constructs the stream x0, x1, etc.

>>> XY = Ty.sequence(symmetric.Ty('x', 'y'))
>>> for x in [XY.now, XY.later.now, XY.later.later.now]: print(x)
x0 @ y0
x1 @ y1
x2 @ y2
Parameters:
  • x (base) –

  • n_steps (int) –

Return type:

Ty

unroll()[source]#

Unroll a stream x0, x1, x2, x3, … to x0 @ x1, x2, x3, ….

>>> U = Ty.sequence('x').unroll()
>>> for x in [U.now, U.later.now, U.later.later.now]: print(x)
x0 @ x1
x2
x3
Return type:

Ty

tensor(other)[source]#

The tensor of streams of types is computed pointwise.

>>> X, Y = map(Ty.sequence, "xy")
>>> XY = X @ Y
>>> for x in [XY.now, XY.later.now, XY.later.later.now]: print(x)
x0 @ y0
x1 @ y1
x2 @ y2
Parameters:

other (Ty) –

Return type:

Ty