hydra.typing module

Types supporting type inference and type reconstruction.

class hydra.typing.FunctionStructure(type_params: Annotated[Sequence[Name], 'Type parameters (from type lambdas)'], params: Annotated[Sequence[Name], 'Value parameters (from lambdas)'], bindings: Annotated[Sequence[Binding], 'Let bindings accumulated from the term'], body: Annotated[Term, 'The body term after removing all lambdas, lets, etc.'], domains: Annotated[Sequence[Type], 'Domain types of the value parameters'], codomain: Annotated[object, 'The return type of the function (if type inference succeeded)'], environment: Annotated[Env, 'Updated environment after processing all bindings'])

Bases: Generic[Env]

A structured representation of a function term’s components, replacing ad-hoc tuples. This captures all the information extracted from peeling lambdas, type lambdas, lets, and type applications from a term.

BINDINGS = Name(value='bindings')
BODY = Name(value='body')
class Builder(_type_params: 'Sequence[hydra.core.Name]' = None, _params: 'Sequence[hydra.core.Name]' = None, _bindings: 'Sequence[hydra.core.Binding]' = None, _body: 'hydra.core.Term' = None, _domains: 'Sequence[hydra.core.Type]' = None, _codomain: 'Optional[hydra.core.Type]' = None, _environment: 'Env' = None)

Bases: Generic[Env]

bindings(bindings)
body(body)
build()
codomain(codomain)
domains(domains)
environment(environment)
params(params)
type_params(type_params)
CODOMAIN = Name(value='codomain')
DOMAINS = Name(value='domains')
ENVIRONMENT = Name(value='environment')
PARAMS = Name(value='params')
TYPE_ = Name(value='hydra.typing.FunctionStructure')
TYPE_PARAMS = Name(value='typeParams')
bindings: Annotated[Sequence[Binding], 'Let bindings accumulated from the term']
body: Annotated[Term, 'The body term after removing all lambdas, lets, etc.']
static builder()
codomain: Annotated[object, 'The return type of the function (if type inference succeeded)']
domains: Annotated[Sequence[Type], 'Domain types of the value parameters']
environment: Annotated[Env, 'Updated environment after processing all bindings']
params: Annotated[Sequence[Name], 'Value parameters (from lambdas)']
type_params: Annotated[Sequence[Name], 'Type parameters (from type lambdas)']
with_bindings(bindings)
with_body(body)
with_codomain(codomain)
with_domains(domains)
with_environment(environment)
with_params(params)
with_type_params(type_params)
class hydra.typing.InferenceContext(fresh_type_variable_count: Annotated[int, 'Counter used to generate distinct fresh type variables during inference'], trace: Annotated[Sequence[SubtermStep], 'The current subterm-path trace, accumulated backwards (head = most-recently-pushed step, corresponding to the deepest point in the descent). At the moment an inference error is constructed, the list is reversed and wrapped into a SubtermPath (root-to-leaf order) and stamped onto the error.'])

Bases: object

State threaded through type inference: the fresh type variable counter and the current subterm-path trace.

class Builder(_fresh_type_variable_count: 'int' = None, _trace: 'Sequence[hydra.paths.SubtermStep]' = None)

Bases: object

build()
fresh_type_variable_count(fresh_type_variable_count)
trace(trace)
FRESH_TYPE_VARIABLE_COUNT = Name(value='freshTypeVariableCount')
TRACE = Name(value='trace')
TYPE_ = Name(value='hydra.typing.InferenceContext')
static builder()
fresh_type_variable_count: Annotated[int, 'Counter used to generate distinct fresh type variables during inference']
trace: Annotated[Sequence[SubtermStep], 'The current subterm-path trace, accumulated backwards (head = most-recently-pushed step, corresponding to the deepest point in the descent). At the moment an inference error is constructed, the list is reversed and wrapped into a SubtermPath (root-to-leaf order) and stamped onto the error.']
with_fresh_type_variable_count(fresh_type_variable_count)
with_trace(trace)
class hydra.typing.InferenceResult(term: Annotated[Term, 'The term which was inferred'], type: Annotated[Type, 'The inferred type of the term'], subst: Annotated[TypeSubst, 'The type substitution resulting from unification'], class_constraints: Annotated[Mapping[Name, TypeVariableConstraints], 'Class constraints discovered during inference (e.g., Ord constraints from Map.lookup)'], context: Annotated[InferenceContext, 'The updated InferenceContext after inference (carries fresh-variable counter and trace)'])

Bases: object

The result of applying inference rules to a term.

class Builder(_term: 'hydra.core.Term' = None, _type: 'hydra.core.Type' = None, _subst: 'TypeSubst' = None, _class_constraints: 'Mapping[hydra.core.Name, hydra.core.TypeVariableConstraints]' = None, _context: 'InferenceContext' = None)

Bases: object

build()
class_constraints(class_constraints)
context(context)
subst(subst)
term(term)
type(type)
CLASS_CONSTRAINTS = Name(value='classConstraints')
CONTEXT = Name(value='context')
SUBST = Name(value='subst')
TERM = Name(value='term')
TYPE = Name(value='type')
TYPE_ = Name(value='hydra.typing.InferenceResult')
static builder()
class_constraints: Annotated[Mapping[Name, TypeVariableConstraints], 'Class constraints discovered during inference (e.g., Ord constraints from Map.lookup)']
context: Annotated[InferenceContext, 'The updated InferenceContext after inference (carries fresh-variable counter and trace)']
subst: Annotated[TypeSubst, 'The type substitution resulting from unification']
term: Annotated[Term, 'The term which was inferred']
type: Annotated[Type, 'The inferred type of the term']
with_class_constraints(class_constraints)
with_context(context)
with_subst(subst)
with_term(term)
with_type(type)
class hydra.typing.Parameter(name: Annotated[Name, 'The name of the parameter'], description: Annotated[object, 'An optional human-readable description of the parameter'], type: Annotated[Type, 'The type of the parameter'], is_lazy: Annotated[bool, 'Whether the parameter must be passed lazily (thunked) at call sites in hosts that distinguish strict from lazy evaluation'])

Bases: object

A named, typed parameter of a term, with optional human-readable description and a flag indicating whether the parameter requires lazy evaluation by hosts which support it.

class Builder(_name: 'hydra.core.Name' = None, _description: 'Optional[str]' = None, _type: 'hydra.core.Type' = None, _is_lazy: 'bool' = None)

Bases: object

build()
description(description)
is_lazy(is_lazy)
name(name)
type(type)
DESCRIPTION = Name(value='description')
IS_LAZY = Name(value='isLazy')
NAME = Name(value='name')
TYPE = Name(value='type')
TYPE_ = Name(value='hydra.typing.Parameter')
static builder()
description: Annotated[object, 'An optional human-readable description of the parameter']
is_lazy: Annotated[bool, 'Whether the parameter must be passed lazily (thunked) at call sites in hosts that distinguish strict from lazy evaluation']
name: Annotated[Name, 'The name of the parameter']
type: Annotated[Type, 'The type of the parameter']
with_description(description)
with_is_lazy(is_lazy)
with_name(name)
with_type(type)
class hydra.typing.Result(description: Annotated[object, 'An optional human-readable description of the result'], type: Annotated[Type, 'The type of the result'])

Bases: object

The result of a term, consisting of a type and an optional human-readable description.

class Builder(_description: 'Optional[str]' = None, _type: 'hydra.core.Type' = None)

Bases: object

build()
description(description)
type(type)
DESCRIPTION = Name(value='description')
TYPE = Name(value='type')
TYPE_ = Name(value='hydra.typing.Result')
static builder()
description: Annotated[object, 'An optional human-readable description of the result']
type: Annotated[Type, 'The type of the result']
with_description(description)
with_type(type)
class hydra.typing.TermSignature(type_parameters: Annotated[Sequence[TypeParameter], 'The type parameters of the term, in order'], parameters: Annotated[Sequence[Parameter], 'The value parameters of the term, in order'], result: Annotated[Result, 'The result of the term'])

Bases: object

A structured signature for a term: an ordered list of type parameters (with optional class constraints), an ordered list of value parameters, and a result. TermSignature is a richer view of TypeScheme: every TermSignature can be converted to a TypeScheme by erasing parameter names, descriptions, and laziness flags.

class Builder(_type_parameters: 'Sequence[TypeParameter]' = None, _parameters: 'Sequence[Parameter]' = None, _result: 'Result' = None)

Bases: object

build()
parameters(parameters)
result(result)
type_parameters(type_parameters)
PARAMETERS = Name(value='parameters')
RESULT = Name(value='result')
TYPE_ = Name(value='hydra.typing.TermSignature')
TYPE_PARAMETERS = Name(value='typeParameters')
static builder()
parameters: Annotated[Sequence[Parameter], 'The value parameters of the term, in order']
result: Annotated[Result, 'The result of the term']
type_parameters: Annotated[Sequence[TypeParameter], 'The type parameters of the term, in order']
with_parameters(parameters)
with_result(result)
with_type_parameters(type_parameters)
class hydra.typing.TermSubst(value: T)

Bases: Node[Mapping[hydra.core.Name, hydra.core.Term]]

A substitution of term variables for terms.

TYPE_ = Name(value='hydra.typing.TermSubst')
class hydra.typing.TypeClass(description: Annotated[str, 'A human-readable description of the type class'])

Bases: object

A type class identifier together with a human-readable description. Type classes are referenced as bare names (e.g. the local name “equality”) in TypeVariableConstraints.classes; the canonical definitions live as term bindings under hydra.classes.

class Builder(_description: 'str' = None)

Bases: object

build()
description(description)
DESCRIPTION = Name(value='description')
TYPE_ = Name(value='hydra.typing.TypeClass')
static builder()
description: Annotated[str, 'A human-readable description of the type class']
with_description(description)
class hydra.typing.TypeConstraint(left: Annotated[Type, 'The left-hand side of the constraint'], right: Annotated[Type, 'The right-hand side of the constraint'], comment: Annotated[str, 'A description of the type constraint which may be used for tracing or debugging'])

Bases: object

An assertion that two types can be unified into a single type.

class Builder(_left: 'hydra.core.Type' = None, _right: 'hydra.core.Type' = None, _comment: 'str' = None)

Bases: object

build()
comment(comment)
left(left)
right(right)
COMMENT = Name(value='comment')
LEFT = Name(value='left')
RIGHT = Name(value='right')
TYPE_ = Name(value='hydra.typing.TypeConstraint')
static builder()
comment: Annotated[str, 'A description of the type constraint which may be used for tracing or debugging']
left: Annotated[Type, 'The left-hand side of the constraint']
right: Annotated[Type, 'The right-hand side of the constraint']
with_comment(comment)
with_left(left)
with_right(right)
class hydra.typing.TypeParameter(name: Annotated[Name, 'The name of the type parameter'], constraints: Annotated[Sequence[TypeClassConstraint], 'Any type class constraints on the type parameter'])

Bases: object

A type parameter of a term, with an optional list of type class constraints.

class Builder(_name: 'hydra.core.Name' = None, _constraints: 'Sequence[hydra.core.TypeClassConstraint]' = None)

Bases: object

build()
constraints(constraints)
name(name)
CONSTRAINTS = Name(value='constraints')
NAME = Name(value='name')
TYPE_ = Name(value='hydra.typing.TypeParameter')
static builder()
constraints: Annotated[Sequence[TypeClassConstraint], 'Any type class constraints on the type parameter']
name: Annotated[Name, 'The name of the type parameter']
with_constraints(constraints)
with_name(name)
class hydra.typing.TypeSubst(value: T)

Bases: Node[Mapping[hydra.core.Name, hydra.core.Type]]

A substitution of type variables for types.

TYPE_ = Name(value='hydra.typing.TypeSubst')