hydra.names module

Functions for working with qualified names.

hydra.names.choose_unique_label(reserved: Set[str], label: str) str

Pick a string label that does not collide with a reserved set, by appending a numeric suffix when necessary.

hydra.names.compact_name(namespaces: Mapping[ModuleName, str], name: Name) str

Given a mapping of namespaces to prefixes, convert a name to a compact string representation.

hydra.names.derived_binding_name(category_prefix: Sequence[str], always_drop_first: bool, n: Name) Name

Generate a binding name for a derived function from a type/term name, given the category’s namespace segments.

hydra.names.derived_definition_name(category_prefix: Sequence[str], always_drop_first: bool, prefix_when_no_namespace: bool, n: Name, local_name: str) Name

Generate a derived element name from a source name’s namespace and an explicit local name.

hydra.names.derived_module_name(category_prefix: Sequence[str], always_drop_first: bool, ns: ModuleName) ModuleName

Generate a derived module name from a source module name, given the category’s namespace segments.

hydra.names.fresh_name(cx: InferenceContext) tuple[Name, InferenceContext]

Generate a fresh type variable name, threading InferenceContext.

hydra.names.fresh_names(n: int, cx: InferenceContext) tuple[Sequence[Name], InferenceContext]

Generate multiple fresh type variable names, threading InferenceContext.

hydra.names.local_name_of(arg_: Name) str

Extract the local part of a name.

hydra.names.module_name_of(arg_: Name) object

Extract the module name of a name, if any.

hydra.names.module_name_to_file_path(case_conv: CaseConvention, ext: FileExtension, ns: ModuleName) str

Convert a module name to a file path with the given case convention and file extension.

hydra.names.name_to_file_path(ns_conv: CaseConvention, local_conv: CaseConvention, ext: FileExtension, name: Name) str

Convert a name to file path, given case conventions for namespaces and local names, and assuming ‘/’ as the file path separator.

hydra.names.normal_type_variable(i: int) Name

Type variable naming convention follows Haskell: t0, t1, etc.

hydra.names.push_subterm_step(step: SubtermStep, cx: InferenceContext) InferenceContext

Prepend a SubtermStep to the InferenceContext’s trace. The trace is accumulated backwards as inference descends through subterms; at error-emission time the list is reversed and wrapped into a SubtermPath stamped onto the error.

hydra.names.qname(ns: ModuleName, name: str) Name

Construct a qualified (dot-separated) name.

hydra.names.qualify_name(name: Name) QualifiedName

Split a dot-separated name into a namespace and local name.

hydra.names.restore_trace(base_cx: InferenceContext, new_cx: InferenceContext) InferenceContext

Restore the original trace from baseCx, while keeping the freshTypeVariableCount from newCx. Used between sibling sub-inferences (e.g. application LHS vs RHS) so that an error in the second sibling doesn’t include the first sibling’s trace path. Returns a new InferenceContext.

hydra.names.unqualify_name(qname: QualifiedName) Name

Convert a qualified name to a dot-separated name.