hydra.overlay.python.dsl.prims module

Python implementations of primitive construction utilities following the Haskell pattern.

class hydra.overlay.python.dsl.prims.TypeVar_(name: str, classes: list[Name] = None)

Bases: object

hydra.overlay.python.dsl.prims.bigint() TermCoder[int]
hydra.overlay.python.dsl.prims.binary() TermCoder[bytes]
hydra.overlay.python.dsl.prims.boolean() TermCoder[bool]
hydra.overlay.python.dsl.prims.build_type_scheme(vars: list[TypeVar_], typ: Type)
hydra.overlay.python.dsl.prims.comparison() TermCoder[Comparison]
hydra.overlay.python.dsl.prims.decimal() TermCoder[Decimal]
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.float32() TermCoder[float]
hydra.overlay.python.dsl.prims.float64() TermCoder[float]
hydra.overlay.python.dsl.prims.float_type() TermCoder[FloatType]
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.int16() TermCoder[int]
hydra.overlay.python.dsl.prims.int32() TermCoder[int]
hydra.overlay.python.dsl.prims.int64() TermCoder[int]
hydra.overlay.python.dsl.prims.int8() TermCoder[int]
hydra.overlay.python.dsl.prims.integer_type() TermCoder[IntegerType]
hydra.overlay.python.dsl.prims.integer_value() TermCoder[IntegerValue]
hydra.overlay.python.dsl.prims.list_(els: TermCoder[X]) TermCoder[tuple]
hydra.overlay.python.dsl.prims.literal() TermCoder[Literal]
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.optional(mel: TermCoder[X]) TermCoder[object]
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.set_(els: TermCoder[X]) TermCoder[frozenset[X]]
hydra.overlay.python.dsl.prims.string() TermCoder[str]
hydra.overlay.python.dsl.prims.term() TermCoder[Term]
hydra.overlay.python.dsl.prims.type_() TermCoder[Type]
hydra.overlay.python.dsl.prims.type_var_names(vars: list[TypeVar_]) list[str]

Get just the variable names from a list of TypeVars.

hydra.overlay.python.dsl.prims.type_vars_to_constraints(vars: list[TypeVar_]) list[tuple[str, list[Name]]]

Convert a list of TypeVars to (name, classes) pairs.

Filters out variables with no constraints.

hydra.overlay.python.dsl.prims.uint16() TermCoder[int]
hydra.overlay.python.dsl.prims.uint32() TermCoder[int]
hydra.overlay.python.dsl.prims.uint64() TermCoder[int]
hydra.overlay.python.dsl.prims.uint8() TermCoder[int]
hydra.overlay.python.dsl.prims.v(name: str) TypeVar_
hydra.overlay.python.dsl.prims.v_eq(name: str) TypeVar_
hydra.overlay.python.dsl.prims.v_frac(name: str) TypeVar_
hydra.overlay.python.dsl.prims.v_integral(name: str) TypeVar_
hydra.overlay.python.dsl.prims.v_num(name: str) TypeVar_
hydra.overlay.python.dsl.prims.v_ord(name: str) TypeVar_
hydra.overlay.python.dsl.prims.variable(v: str) TermCoder[Term]

TermCoder for type variables.

hydra.overlay.python.dsl.prims.void() TermCoder[Term]

TermCoder for the void type. Never legitimately exercised: void has no inhabitants.