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 ann argument may be either a Mapping[str, Term] (wrapped as a TermMap per Hydra’s map convention) or an arbitrary Term if 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.bigint() Type

Arbitrary-precision integer type.

hydra.overlay.python.dsl.types.binary() Type

Binary data type.

hydra.overlay.python.dsl.types.boolean() Type

Boolean type.

hydra.overlay.python.dsl.types.decimal() Type

Arbitrary-precision exact decimal type.

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.float32() Type

32-bit floating point type.

hydra.overlay.python.dsl.types.float64() Type

64-bit floating point type.

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.int16() Type

16-bit signed integer type.

hydra.overlay.python.dsl.types.int32() Type

32-bit signed integer type.

hydra.overlay.python.dsl.types.int64() Type

64-bit signed integer type.

hydra.overlay.python.dsl.types.int8() Type

8-bit signed integer type.

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.non_negative_int32() Type

Non-negative 32-bit integer type.

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.string() Type

String type.

hydra.overlay.python.dsl.types.uint16() Type

16-bit unsigned integer type.

hydra.overlay.python.dsl.types.uint32() Type

32-bit unsigned integer type.

hydra.overlay.python.dsl.types.uint64() Type

64-bit unsigned integer type.

hydra.overlay.python.dsl.types.uint8() Type

8-bit unsigned integer type.

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.unit() Type

Unit type (empty record type).

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”)

hydra.overlay.python.dsl.types.void() Type

Void type (uninhabited type, dual of unit).

hydra.overlay.python.dsl.types.wrap(t: Type | Binding | str) Type

Create a wrapped type (newtype) over a base type.

Example: wrap(string())

hydra.overlay.python.dsl.types.wrap_with_name(name: Name, t: Type) Type

Create a wrapped type (newtype) with a provided base type and type name.

Example: wrap_with_name(Name(“Email”), string())