home Anil Madhavapeddy, Professor of Planetary Computing  

A hardware description language using OCaml effects

This is an idea proposed in 2025 as a Cambridge Computer Science Part III or MPhil project, and is available for being worked on. It may be co-supervised with KC Sivaramakrishnan and Andy Ray.

Programming FPGAs using functional programming languages is a very good fit for the problem domain. OCaml has the HardCaml ecosystem to express hardware designs in OCaml, make generic designs using the power of the language, then simulate designs and convert them to Verilog or VHDL.

HardCaml is very successfully used in production at places like Jane Street, but needs quite a lot of prerequisite knowledge about the full OCaml language. In particular, it makes very heavy use of the module system in order to build up the circuit description as an OCaml data structure.

Instead of building up a circuit as the output of the OCaml program, it would be very cool if we could directly implement the circuit as OCaml code by evaluating it. This is an approach that works very successfully in the Clash Haskell HDL, as described in this thesis. Clash uses a number of advanced Haskell type-level features to encode fixed-length vectors (very convenient for hardware description) and has an interactive REPL that allows for exploration without requiring a separate test bench.

The question for this project is whether the new effect handlers in OCaml 5.0 might be suitable for using OCaml as a host language for a tracing-style hardware description language. We would explore several elements using OCaml 5:

This project will require a deep interest in programming language design and implementation, and an enthusiasm for learning more about digital hardware. There are quite a few good usecases for using heterogenous hardware like FPGAs these days. There's a great Signals and Threads episode on programmable hardware with Andy Ray that should give you more useful background knowledge as well.

# 1st Mar 2025   iconideas fpgas idea-available idea-hard ocaml systems

Related News