FunctionType#

class hugr.tys.FunctionType(input: list[~hugr.tys.Type], output: list[~hugr.tys.Type], extension_reqs: list[str] = <factory>)[source]#

Bases: Type

A function type, defined by input types, output types and extension requirements.

Methods

empty

Generate an empty function type.

endo

Function type with the same input and output types.

flip

Return a new function type with input and output types swapped.

resolve

Resolve types in the function type using the given registry.

type_arg

The TypeTypeArg for this type.

type_bound

The bound of this type.

Attributes

input

output

extension_reqs

classmethod empty() FunctionType[source]#

Generate an empty function type.

Example

>>> FunctionType.empty()
FunctionType([], [])
classmethod endo(tys: list[Type], extension_reqs: list[str] | None = None) FunctionType[source]#

Function type with the same input and output types.

Example

>>> FunctionType.endo([Qubit])
FunctionType([Qubit], [Qubit])
flip() FunctionType[source]#

Return a new function type with input and output types swapped.

Example

>>> FunctionType([Qubit], [Bool]).flip()
FunctionType([Bool], [Qubit])
resolve(registry: ext.ExtensionRegistry) FunctionType[source]#

Resolve types in the function type using the given registry.

type_arg() TypeTypeArg#

The TypeTypeArg for this type.

Example

>>> Qubit.type_arg()
TypeTypeArg(ty=Qubit)
type_bound() TypeBound[source]#

The bound of this type.

Example

>>> Tuple(Bool, Bool).type_bound()
<TypeBound.Copyable: 'C'>
>>> Tuple(Qubit, Bool).type_bound()
<TypeBound.Any: 'A'>