hydra.overlay.python.dsl.prims module
Python implementations of primitive construction utilities following the Haskell pattern.
- hydra.overlay.python.dsl.prims.comparison() TermCoder[Comparison]
- hydra.overlay.python.dsl.prims.default_fallback_primitive(definition: PrimitiveDefinition) Primitive
Build a Primitive for a kernel primitive with no native Python implementation, but which declares a portable, cross-compilable defaultImplementation term (see hydra.lib.defaults.default_implementations()). Its implementation evaluates that term against the call arguments via reduce_term, rather than running hand-written Python logic. Requires definition.default_implementation to be Given (the caller is expected to check this before constructing the fallback).
Note: default_implementation is already a real, directly reducible Term (e.g. TermLambda(…)), not an encoded/reified term-as-data requiring a decode step — confirmed by reading the published host’s hydra.overlay.python.lib.lists.take_while().default_implementation. This differs from the Haskell kernel source’s Lib/Defaults.hs, which reifies each implementation via EncodeCore.term specifically because a single TermMap can’t hold heterogeneously-typed executable terms; the Python code generator resolves that reification at generation time instead.
- hydra.overlay.python.dsl.prims.default_primitive_definition(name: Name, typ, lazy_args: list[int] = []) PrimitiveDefinition
Build a PrimitiveDefinition with default metadata (mirrors Haskell default). For #156.
lazy_args: 0-based positions of value parameters that must be passed lazily (thunked) at call sites in hosts that distinguish strict from lazy evaluation (#391). type_scheme_to_term_signature cannot infer laziness, so the per-primitive lazy_args records it for coders. Mirrors Hydra.Dsl.Prims.lazyArgs on the Haskell host.
- hydra.overlay.python.dsl.prims.either(left_coder: TermCoder[X], right_coder: TermCoder[Y]) TermCoder[object]
- hydra.overlay.python.dsl.prims.float_value() TermCoder[FloatValue]
- hydra.overlay.python.dsl.prims.function(dom: TermCoder[X], cod: TermCoder[Y]) TermCoder[Callable[[X], Y]]
TermCoder for function values (not actually encodable/decodable).
- hydra.overlay.python.dsl.prims.function_with_reduce(reduce: Callable, dom: TermCoder[X], cod: TermCoder[Y]) TermCoder[Callable[[X], Y]]
TermCoder for function types, using a reducer to bridge term-level functions to native functions.
The reduce parameter should be (cx, g, term) -> Either[Error, Term].
- hydra.overlay.python.dsl.prims.integer_type() TermCoder[IntegerType]
- hydra.overlay.python.dsl.prims.integer_value() TermCoder[IntegerValue]
- hydra.overlay.python.dsl.prims.literal_type() TermCoder[LiteralType]
- hydra.overlay.python.dsl.prims.map_(keys: TermCoder[X], values: TermCoder[Y]) TermCoder[FrozenDict[X, Y]]
- hydra.overlay.python.dsl.prims.other_err(cx: InferenceContext, msg: str) Error
Create an Error (Other) from a string message.
- hydra.overlay.python.dsl.prims.pair(first_coder: TermCoder[X], second_coder: TermCoder[Y]) TermCoder[tuple[X, Y]]
- hydra.overlay.python.dsl.prims.prim0(name: Name, value: Callable[[], A], variables: list[TypeVar_], output: TermCoder[A]) Primitive
Create a 0-argument primitive function.
- hydra.overlay.python.dsl.prims.prim1(name: Name, compute: Callable[[A], B], variables: list[TypeVar_], input1: TermCoder[A], output: TermCoder[B]) Primitive
Create a 1-argument primitive function.
- hydra.overlay.python.dsl.prims.prim2(name: Name, compute: Callable[[A, B], C], variables: list[TypeVar_], input1: TermCoder[A], input2: TermCoder[B], output: TermCoder[C], lazy_args: list[int] = []) Primitive
Create a 2-argument primitive function. lazy_args: 0-based lazy parameter positions (#391).
- hydra.overlay.python.dsl.prims.prim3(name: Name, compute: Callable[[A, B, C], D], variables: list[TypeVar_], input1: TermCoder[A], input2: TermCoder[B], input3: TermCoder[C], output: TermCoder[D], lazy_args: list[int] = []) Primitive
Create a 3-argument primitive function. lazy_args: 0-based lazy parameter positions (#391).
- hydra.overlay.python.dsl.prims.type_var_names(vars: list[TypeVar_]) list[str]
Get just the variable names from a list of TypeVars.