hydra.overlay.python.dsl.types module
A domain-specific language for constructing Hydra types in Python.
- hydra.overlay.python.dsl.types.annot(ann, t: Type) Type
Attach an annotation to a type.
The
annargument may be either aMapping[str, Term](wrapped as a TermMap per Hydra’s map convention) or an arbitraryTermif the application wants a non-map annotation shape.Example: annot({“min”: int32_term(0), “max”: int32_term(100)}, int32())
- hydra.overlay.python.dsl.types.apply(lhs: Type, rhs: Type) Type
Apply a type to a type argument.
Example: apply(var(“f”), int32())
- hydra.overlay.python.dsl.types.apply_many(ts: Sequence[Type]) Type
Apply a type to multiple type arguments (takes types as a sequence).
- hydra.overlay.python.dsl.types.applys(t: Type, ts: Sequence[Type]) Type
Apply a type to multiple type arguments.
Example: applys(var(“Either”), [string(), int32()])
- hydra.overlay.python.dsl.types.either(left: Type | Binding | str, right: Type | Binding | str) Type
Create an either type (a choice between two types).
Example: either(string(), int32())
- hydra.overlay.python.dsl.types.enum(names: Sequence[str]) Type
Create an enum type with the given variant names (conventionally in camelCase).
Example: enum([“red”, “green”, “blue”])
- hydra.overlay.python.dsl.types.field(fn: str, t: Type | Binding | str) FieldType
Create a field with the given name and type.
The type argument can be a Type, a Binding (auto-coerced to TypeVariable), or a string (auto-coerced to TypeVariable).
Example: field(“age”, int32()) Example: field(“name”, name_binding) # reference another type by its Binding
- hydra.overlay.python.dsl.types.float_(ftype: FloatType) Type
Create a floating point type with the specified precision.
- hydra.overlay.python.dsl.types.forall(v: str, body: Type) Type
Create a universally quantified type (polymorphic type) with a single variable.
Example: forall(“a”, function(var(“a”), var(“a”))) This creates the polymorphic identity function type: forall a. a -> a Universal quantification introduces type variables that can be used in the body.
- hydra.overlay.python.dsl.types.foralls(vs: Sequence[str], body: Type) Type
Universal quantification with multiple variables.
Example: foralls([“a”, “b”], function(var(“a”), var(“b”)))
- hydra.overlay.python.dsl.types.function(dom: Type | Binding | str, cod: Type | Binding | str) Type
Create a function type.
Example: function(int32(), string())
- hydra.overlay.python.dsl.types.function_many(ts: Sequence[Type]) Type
Create an n-ary function type.
Example: function_many([int32(), string(), boolean()])
- hydra.overlay.python.dsl.types.integer(itype: IntegerType) Type
Create an integer type with the specified bit width.
- hydra.overlay.python.dsl.types.list_(t: Type | Binding | str) Type
List type.
Example: list_(string()) Example: list_(field_type_binding) # reference another type by its Binding
- hydra.overlay.python.dsl.types.literal(t: LiteralType) Type
Literal primitive type.
- hydra.overlay.python.dsl.types.map_(k: Type | Binding | str, v: Type | Binding | str) Type
Map/dictionary type with key and value types.
Example: map_(string(), int32()) Example: map_(name_binding, term_binding)
- hydra.overlay.python.dsl.types.maybe(t: Type | Binding | str) Type
optional (nullable) type.
Example: maybe(string())
- hydra.overlay.python.dsl.types.mono(t: Type) TypeScheme
Create a monomorphic type scheme.
Example: mono(int32())
- hydra.overlay.python.dsl.types.optional(t: Type | Binding | str) Type
Optional (nullable) type (alias for ‘maybe’).
Example: optional(string())
- hydra.overlay.python.dsl.types.pair(a: Type | Binding | str, b: Type | Binding | str) Type
Create a pair type.
Example: pair(string(), int32())
- hydra.overlay.python.dsl.types.poly(vs: Sequence[str], t: Type) TypeScheme
Create a polymorphic type scheme with explicit type variables.
Example: poly([“a”, “b”], function(var(“a”), var(“b”))) This represents a type forall a b. a -> b that can be instantiated with different types.
- hydra.overlay.python.dsl.types.poly_constrained(vs_with_constraints: Sequence[tuple[str, list[Name]]], t: Type) TypeScheme
Create a polymorphic type scheme with type variables and class constraints.
- Example: poly_constrained([(“k”, [Name(“ordering”)]), (“v”, [])],
function(var(“k”), var(“v”)))
- hydra.overlay.python.dsl.types.product(ts: Sequence[Type]) Type
Create a product type using nested pairs.
Example: product([string(), int32(), boolean()]) creates pair(string(), pair(int32(), boolean()))
- hydra.overlay.python.dsl.types.record(fields: Sequence[FieldType]) Type
Create a record type with the given fields.
Example: record([field(“name”, string()), field(“age”, int32())])
- hydra.overlay.python.dsl.types.record_with_name(tname: Name, fields: Sequence[FieldType]) Type
Create a record type with the given fields and a provided type name.
Example: record_with_name(Name(“Person”), [field(“name”, string()), field(“age”, int32())])
- hydra.overlay.python.dsl.types.set_(t: Type | Binding | str) Type
Set type.
Example: set_(string())
- hydra.overlay.python.dsl.types.union(fields: Sequence[FieldType]) Type
Create a union type with the given variants and the default type name.
Example: union([field(“success”, int32()), field(“failure”, string())]) This creates a tagged union type (sum type with named variants).
- hydra.overlay.python.dsl.types.use(b: Binding) Type
Convert a Binding to a Type by extracting its name as a TypeVariable.
This mirrors Haskell’s AsType Binding instance, enabling type definitions to reference other types by their Binding directly.
Example: use(name_binding) # equivalent to variable(“hydra.core.Name”)
- hydra.overlay.python.dsl.types.var(name: str) Type
Create a type variable with the given name (alias for ‘variable’).
Example: var(“a”)
- hydra.overlay.python.dsl.types.variable(name: str) Type
Create a type variable with the given name.
Example: variable(“a”)