Function#

class discopy.python.Function(inside, dom, cod)[source]#

Bases: Composable[tuple[type, …]], Whiskerable

A function is a callable inside with a pair of types dom and cod.

Parameters:
  • inside (Callable) – The callable Python object inside the function.

  • dom (tuple[type, ...]) – The domain of the function, i.e. its input type.

  • cod (tuple[type, ...]) – The codomain of the function, i.e. its output type.

Summary

id()

The identity function on a given tuple of types dom.

then(other)

The sequential composition of two functions, called with >>.

tensor(other)

The parallel composition of two functions, called with @.

swap(x, y)

The function for swapping two tuples of types x and y.

copy(x[, n])

The function for making n copies of a tuple of types x.

discard(dom)

The function discarding a tuple of types, i.e. making zero copies.

ev(base, exponent[, left])

The evaluation function, i.e. take a function and apply it to an argument.

curry([n, left])

Currying, i.e. turn a binary function into a function-valued function.

uncurry([left])

Uncurrying, i.e. turn a function-valued function into a binary function.

fix([n])

The parameterised fixed point of a function.

trace([n, left])

The trace of a function.

id()[source]#

The identity function on a given tuple of types dom.

Parameters:

dom (python.Ty) – The typle of types on which to take the identity.

Return type:

Function

then(other)[source]#

The sequential composition of two functions, called with >>.

Parameters:

other (Function) – The other function to compose in sequence.

Return type:

Function

tensor(other)[source]#

The parallel composition of two functions, called with @.

Parameters:

other (Function) – The other function to compose in sequence.

Return type:

Function

static swap(x, y)[source]#

The function for swapping two tuples of types x and y.

Parameters:
  • x (tuple[type, ...]) – The tuple of types on the left.

  • y (tuple[type, ...]) – The tuple of types on the right.

Return type:

Function

static braid(x, y)#

The function for swapping two tuples of types x and y.

Parameters:
  • x (tuple[type, ...]) – The tuple of types on the left.

  • y (tuple[type, ...]) – The tuple of types on the right.

Return type:

Function

static copy(x, n=2)[source]#

The function for making n copies of a tuple of types x.

Parameters:
  • x (tuple[type, ...]) – The tuple of types to copy.

  • n – The number of copies.

Return type:

Function

static discard(dom)[source]#

The function discarding a tuple of types, i.e. making zero copies.

Parameters:

dom (tuple[type, ...]) – The tuple of types to discard.

Return type:

Function

static ev(base, exponent, left=True)[source]#

The evaluation function, i.e. take a function and apply it to an argument.

Parameters:
  • base (tuple[type, ...]) – The output type.

  • exponent (tuple[type, ...]) – The input type.

  • left – Whether to take the function on the left or right.

Return type:

Function

curry(n=1, left=True)[source]#

Currying, i.e. turn a binary function into a function-valued function.

Parameters:
  • n – The number of types to curry.

  • left – Whether to curry on the left or right.

Return type:

Function

uncurry(left=True)[source]#

Uncurrying, i.e. turn a function-valued function into a binary function.

Parameters:

left – Whether to uncurry on the left or right.

Return type:

Function

fix(n=1)[source]#

The parameterised fixed point of a function.

Parameters:

n – The number of types to take the fixed point over.

Return type:

Function

trace(n=1, left=False)[source]#

The trace of a function.

Parameters:

n – The number of types to trace over.