Function
Function#
- class discopy.python.Function(inside, dom, cod)[source]#
Bases:
Composable
[tuple
[type
, …]],Whiskerable
A function is a callable
inside
with a pair of typesdom
andcod
.- 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.
- Return type
None
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
andy
.copy
(x[, n])The function for making
n
copies of a tuple of typesx
.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
- static swap(x, y)[source]#
The function for swapping two tuples of types
x
andy
.- Parameters
x (tuple[type, ...]) – The tuple of types on the left.
y (tuple[type, ...]) – The tuple of types on the right.
- Return type
- static braid(x, y)#
The function for swapping two tuples of types
x
andy
.- Parameters
x (tuple[type, ...]) – The tuple of types on the left.
y (tuple[type, ...]) – The tuple of types on the right.
- Return type
- static copy(x, n=2)[source]#
The function for making
n
copies of a tuple of typesx
.- Parameters
x (tuple[type, ...]) – The tuple of types to copy.
n – The number of copies.
- Return type
- 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
- 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
- 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
- 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