hydra.scala.coder module
Scala code generator: converts Hydra modules to Scala source code.
- hydra.scala.coder.apply_var(fterm: Term, avar: Name) Term
Apply a variable to a term, performing substitution for lambdas.
- hydra.scala.coder.collect_type_vars(typ: Type) Set[Name]
Collect the set of free type variables occurring in a type (#589).
- hydra.scala.coder.collect_type_vars_go(t: Type) Set[Name]
Recursively collect free type variables from a type (#589).
- hydra.scala.coder.construct_module(overlay_subs: Set[str], cx: T0, g: Graph, mod: Module, defs: Sequence[Definition]) object
Construct a Scala package from a Hydra module and its definitions.
- hydra.scala.coder.correct_type_apps(name: Name, fallback_type_apps: Sequence[Type], g: Graph) object
Filter/rewrite a raw type-application list against callee-scheme over-generalization (#589).
- hydra.scala.coder.count_function_params(t: Type) int
Count the curried function parameters of a type (#589).
- hydra.scala.coder.detect_accumulator_unification(doms: Sequence[Type], cod: Type, tparams: Sequence[Name]) Mapping[Name, Type]
Detect callee-scheme type vars forced together/to-concrete by the callee’s own domain shape (#589).
- hydra.scala.coder.direct_ref_substitution(direct_input_vars: Set[T0], cod_var: object, grouped: Mapping[T0, Sequence[T0]]) Mapping[T0, T0]
Compute the direct-return substitution over grouped accumulator pairs (#589).
- hydra.scala.coder.direct_ref_substitution_process_group(direct_input_vars: Set[T0], cod_var: object, subst: Mapping[T0, T0], in_var: T0, out_vars: Sequence[T0]) Mapping[T0, T0]
Unify safe co-occurring vars onto inVar for the direct-return accumulator pattern (#589).
- hydra.scala.coder.drop_domains(n: int, t: Type) Type
Drop N domain types from a function type, returning the remaining type.
- hydra.scala.coder.encode_case(overlay_subs: Set[str], cx: T0, g: Graph, ftypes: Mapping[Name, Type], sn: object, f: CaseAlternative) object
Encode a case branch.
- hydra.scala.coder.encode_complex_term_def(overlay_subs: Set[str], cx: T0, g: Graph, lname: str, term: Term, typ: Type) object
Encode a complex term definition with proper parameter types from the type signature.
- hydra.scala.coder.encode_function(overlay_subs: Set[str], cx: T0, g: Graph, meta: Mapping[Name, Term], fun_term: Term, arg: object) object
Encode a Hydra function-valued term (lambda, project, cases, or unwrap) as a Scala expression.
- hydra.scala.coder.encode_let_binding(overlay_subs: Set[str], cx: T0, g: Graph, outer_type_vars: Set[Name], b: Binding) object
Encode a let binding as a val or def declaration. outerTypeVars are type params from the enclosing scope.
- hydra.scala.coder.encode_literal(cx: T0, g: T1, av: Literal) object
Encode a literal value as a Scala literal.
- hydra.scala.coder.encode_local_def(overlay_subs: Set[str], cx: T0, g: Graph, outer_type_vars: Set[Name], lname: str, term: Term, typ: Type) object
Encode a local def. outerTypeVars are type params already in scope (don’t redeclare them).
- hydra.scala.coder.encode_term(overlay_subs: Set[str], cx: T0, g: Graph, term0: Term) object
Encode a Hydra term as a Scala expression.
- hydra.scala.coder.encode_term_definition(overlay_subs: Set[str], cx: T0, g: Graph, td: TermDefinition) object
Encode a term definition as a Scala statement.
- hydra.scala.coder.encode_type_definition(cx: T0, g: T1, td: TypeDefinition) object
Encode a type definition as a Scala statement.
- hydra.scala.coder.encode_typed_param(cx: T0, g: T1, pair: tuple[Name, Type]) object
Encode a parameter with its type annotation.
- hydra.scala.coder.encode_untype_application_term(overlay_subs: Set[str], cx: InferenceContext, g: Graph, term: Term) object
Encode an untyped application term by first inferring types.
- hydra.scala.coder.extract_codomain(t: Type) Type
Extract the final return type from a function type.
- hydra.scala.coder.extract_direct_return(tparam_set: Set[Name], t: Type) Sequence[tuple[Name, Name]]
Extract direct-return (input-var, output-var) pairs from a domain type (#589).
- hydra.scala.coder.extract_direct_return_go(tparam_set: Set[Name], t: Type) Sequence[tuple[Name, Name]]
Recursive worker for extractDirectReturn (#589).
- hydra.scala.coder.extract_domains(t: Type) Sequence[Type]
Extract domain types from a function type.
- hydra.scala.coder.extract_in_out_pair(t: Type) Sequence[tuple[Name, Name]]
Extract an (input-var, output-var) accumulator pair from a domain type (#589).
- hydra.scala.coder.extract_let_bindings(t: Term) Sequence[Binding]
Extract let bindings from a term.
- hydra.scala.coder.field_to_enum_case(cx: T0, g: T1, parent_name: str, tparams: Sequence[ParamType], ft: FieldType) object
Convert a field type to a Scala enum case.
- hydra.scala.coder.field_to_param(cx: T0, g: T1, ft: FieldType) object
Convert a field type to a Scala parameter.
- hydra.scala.coder.filter_by_flags(xs: Sequence[T0], flags: Sequence[bool]) Sequence[T0]
Keep elements of xs whose corresponding flag is true (#589).
- hydra.scala.coder.find_domain(cx: T0, g: Graph, meta: Mapping[Name, Term]) object
Find the domain type from annotations.
- hydra.scala.coder.find_imports(overlay_subs: Set[str], cx: T0, g: Graph, mod: Module) object
Find import statements for the module.
- hydra.scala.coder.find_pair_first(t: Type) object
If t is Pair(var, _), return the first component’s variable name (#589).
- hydra.scala.coder.find_sdom(cx: T0, g: Graph, meta: Mapping[Name, Term]) object
Find the Scala domain type for a function from annotations.
- hydra.scala.coder.find_self_ref_var(grouped: Mapping[T0, Sequence[T0]]) object
Find a type variable that is its own accumulator output, if any (#589).
- hydra.scala.coder.group_pairs_by_first(pairs: Sequence[tuple[T0, T1]]) Mapping[T0, Sequence[T1]]
Group a list of pairs into a map keyed by first component (#589).
- hydra.scala.coder.is_simple_name(name: Name) bool
True if a type-variable name has no namespace qualifier (#589).
- hydra.scala.coder.module_to_scala(overlay_subs: Set[str], mod: Module, defs: Sequence[Definition], cx: T0, g: Graph) object
Convert a Hydra module to Scala source code.
- hydra.scala.coder.name_map_to_type_map(m: Mapping[T0, Name]) Mapping[T0, Type]
Lift a Name->Name substitution map to a Name->Type map (#589).
- hydra.scala.coder.peel_domain_types(n: int, t: Type) tuple[Sequence[Type], Type]
Peel up to n curried domain types off a function type (#589).
- hydra.scala.coder.self_ref_substitution(grouped: Mapping[T0, Sequence[T0]]) Mapping[T0, T0]
Compute the self-reference substitution over grouped accumulator pairs (#589).
- hydra.scala.coder.self_ref_substitution_process_group(subst: Mapping[T0, T0], in_var: T0, out_vars: Sequence[T0]) Mapping[T0, T0]
Unify every co-occurring var onto inVar when inVar is its own accumulator output (#589).
- hydra.scala.coder.strip_wrap_eliminations(t: Term) Term
Strip wrap eliminations from terms (newtypes are erased in Scala).
- hydra.scala.coder.substitute_type_vars_with_types(subst: Mapping[Name, Type], t: Type) Type
Substitute type variables in t per subst (#589).
- hydra.scala.coder.substitute_type_vars_with_types_go(subst: Mapping[Name, Type], t: Type) Type
Recursive worker for substituteTypeVarsWithTypes (#589).
- hydra.scala.coder.to_el_import(ns: ModuleName) Stat
Create an element import statement.
- hydra.scala.coder.to_prim_import(overlay_subs: Set[str], ns: ModuleName) Stat
Create a primitive import statement.