Skip to main content

Hydra-Kernel

The Hydra kernel — the code that fundamentally defines what Hydra is and how it operates. Hydra's core data types (Type, Term, Graph, Module, etc.) and its fundamental programming logic (inference, checking, reduction, rewriting, validation, the coder framework, the primitive standard library) live here. The kernel uses the Hydra language to define the Hydra language itself.

Every other Hydra package is peripheral, adding capabilities like Haskell or Java support, RDF or property graph functionality, and so on. Every package depends on hydra-kernel; every host language imports a generated form of it.

Hydra is a functional programming language based on the LambdaGraph data model, exploring an isomorphism between typed lambda calculus and labeled hypergraphs. See the main Hydra README for project overview and use cases.

What lives here

packages/hydra-kernel/ is the DSL source of truth for the kernel. There is no generated output in this package — only the hand-written DSL modules that describe what the kernel is. Generated kernels for each host language live in dist/<lang>/hydra-kernel/.

Type modules

src/main/haskell/Hydra/Sources/Kernel/Types/ defines the core data structures:

  • Core.hs — the central grammar: Term, Type, Literal, Function, Elimination, plus annotations and type schemes. The most important file in the kernel.
  • Graph.hsGraph, Primitive, Library, TermCoder — the runtime containers for terms, types, and primitive bindings. Each Primitive pairs a universal PrimitiveDefinition (from Packaging.hs) with a host-specific native implementation.
  • Packaging.hsPackage, Module, Definition, module/package dependencies, and the EntityMetadata documentation/lifecycle types. See the Packaging wiki page for the model.
  • Coders.hs — the bidirectional Coder framework that every per-language coder builds on, plus Adapter (which transforms both type and value).
  • Errors.hs — the unified error taxonomy used across inference, validation, and code generation.
  • Ast.hs — variant tags used by validators and serializers.
  • Mantle.hs — type-system internals (TypeScheme, kind, class constraints).
  • Subdirectories (Error/, Json/, Show/) — submodule groupings for error variants, JSON encoding, and pretty-printing.

Term modules

src/main/haskell/Hydra/Sources/Kernel/Terms/ defines the algorithms:

  • Inference.hs — Algorithm W (Hindley–Milner) with class constraints, type schemes, and Hydra-specific extensions for nominal terms.
  • Checking.hs — type checking; runs after inference and validates results.
  • Reduction.hs — beta/eta reduction, including tail-call detection used by the Python and Java coders (see TCO implementation).
  • Rewriting.hs — free-variable analysis, substitution, term traversal.
  • Analysis.hsisSelfTailRecursive and related shared analyses.
  • Validate/ — module-level validation rules (hydra.validate.*).
  • Sorting.hs, Topology.hs — Tarjan SCC over module/term dependency graphs.
  • Dsls.hs, Generation.hs — the meta-level pieces that drive sync pipelines.
  • Lexical.hs, Names.hs, Scoping.hs, Variables.hs — binder hygiene, name generation, scope handling.

Library modules — the canonical primitive registry

src/main/haskell/Hydra/Sources/Kernel/Lib/ is the primitive registry: one module per hydra.lib.<sub> namespace, declaring every primitive in that namespace as a PrimitiveDefinition (name, description, signature, isPure / isTotal flags, and an optional cross-compilable default implementation in Hydra terms).

The 21 namespaces — Chars, Defaults, Effects, Eithers, Equality, Files, Functions, Hashing, Lists, Literals, Logic, Maps, Math, Optionals, Ordering, Pairs, Regex, Sets, Strings, System, Text — together declare ~290 primitives (see the lexicon for the authoritative count). See docs/hydra-lexicon.txt for the full signature list, and docs/recipes/adding-primitives.md for the recipe to add a new one.

Host-side primitive registries — including the Haskell-side Hydra/Overlay/Haskell/Libraries.hs (in overlay/haskell since #473, relocated under the hydra.overlay.<lang>.* namespace by #501) that pairs each native implementation with a primitive name — are distinct from this canonical registry: they provide host-specific implementations and derive each primitive's name from its generated PrimitiveDefinition (the single source of truth), rather than re-declaring it.

Code organization

The kernel package contains DSL sources only. Generated kernels and runtime helpers live in adjacent directories:

Where What
packages/hydra-kernel/src/main/haskell/Hydra/Sources/ Kernel DSL sources (this package)
heads/haskell/src/main/haskell/Hydra/Dsl/ Hand-written Haskell DSL helpers used to write the sources
overlay/haskell/hydra-kernel/src/main/haskell/Hydra/Overlay/Haskell/Lib/ Hand-written Haskell primitive implementations (overlaid onto the kernel dist)
dist/haskell/hydra-kernel/ Generated Haskell kernel (Hydra/Core.hs, Hydra/Graph.hs, etc.)
dist/java/hydra-kernel/ Generated Java kernel (hydra.core.*, hydra.graph.*, etc.)
dist/python/hydra-kernel/ Generated Python kernel
dist/scala/hydra-kernel/ Generated Scala kernel
dist/{clojure,common-lisp,emacs-lisp,scheme}/hydra-kernel/ Generated Lisp-dialect kernels
dist/typescript/hydra-kernel/ Generated TypeScript kernel
dist/json/hydra-kernel/ Generated JSON kernel — language-agnostic interchange

For the broader packages/heads/dist pattern, see the Code organization wiki page.

How the kernel is regenerated

The kernel is generated from these DSL sources via bin/sync.sh. After editing a file under Hydra/Sources/Kernel/, run:

heads/haskell/bin/sync-haskell.sh   # regenerate Haskell kernel, run stack test
bin/sync.sh                # regenerate every target language's kernel and tests

See Generating code with Hydra for the full pipeline and The Hydra build system for the cache model.

Extending the kernel

Three of the most common kernel-modification tasks have dedicated recipes:

For the DSL idioms used to write these sources, see the Haskell DSL guide.

See also

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hydra_kernel-0.17.4.tar.gz (689.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hydra_kernel-0.17.4-py3-none-any.whl (657.9 kB view details)

Uploaded Python 3

File details

Details for the file hydra_kernel-0.17.4.tar.gz.

File metadata

  • Download URL: hydra_kernel-0.17.4.tar.gz
  • Upload date:
  • Size: 689.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for hydra_kernel-0.17.4.tar.gz
Algorithm Hash digest
SHA256 2a8cd2b8d4a7fbdd751eca1829a88775260f97fc3e1023c49f7bfa237bf17f06
MD5 ec576949dc3e6a629fe39510564e2af1
BLAKE2b-256 6d93c9348ba7cb0a715402b106269daaae44c7707ef2b8b7e6b80b15254f53b9

See more details on using hashes here.

File details

Details for the file hydra_kernel-0.17.4-py3-none-any.whl.

File metadata

  • Download URL: hydra_kernel-0.17.4-py3-none-any.whl
  • Upload date:
  • Size: 657.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.4

File hashes

Hashes for hydra_kernel-0.17.4-py3-none-any.whl
Algorithm Hash digest
SHA256 66904db7113bd7a5e9cca9105d11ccbd1161c9def73db45f91d2fdf89429412d
MD5 484b281557a47090b21cad124ee40215
BLAKE2b-256 6cc0d4c3f33cae0ce4292d07a3ec76382ac6243b1e3fb12fea89095c90432f4c

See more details on using hashes here.

Release history Release notifications | RSS feed

0.17.6

2 files

0.17.5

2 files

This release

0.17.4 This release

2 files

0.17.3

2 files

0.17.2

2 files

0.17.1

2 files

0.17.0

2 files

0.16.1

2 files

0.16.0

2 files

0.15.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page