FunctionType

class hugr.tys.FunctionType(input: list[Type], output: list[Type])[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.

to_model

Convert the type to a model Term.

type_arg

The TypeTypeArg for this type.

type_bound

The bound of this type.

Attributes

input

output

classmethod empty() FunctionType[source]

Generate an empty function type.

Example

>>> FunctionType.empty()
FunctionType([], [])
classmethod endo(tys: list[Type]) 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.

to_model() Term[source]

Convert the type to a model Term.

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'>