Skip to main content

Myriad

A code generation and meta-programming tool for F#.

Myriad is a code generation and meta-programming tool for F#, built to make compile-time codegen a first-class, idiomatic part of the language rather than a workaround.

F# doesn’t have macros, and Type Providers solve a narrower problem than general-purpose code generation. Myriad fills that gap: annotate a type, point it at a plugin, and it emits real F# (discriminated unions, records, lenses), generated before compilation and optimized like everything else. No reflection at runtime, nothing at the type level you can’t inspect.

It ships with three plugins out of the box: fields (inspired by OCaml’s ppx_fields_conv), lenses (functional getter/setter pairs), and DuCases (toString/fromString/toTag/isX helpers for discriminated unions). It runs via MSBuild or as a standalone CLI, and is extensible with your own plugins for whatever pattern you’re tired of hand-writing. It’s Apache-2.0 licensed, actively maintained (it passed 1.0 in September 2026, making the public API stable), and has grown a small ecosystem of third-party plugins (SqlHydra, JsonWrapper, TypeSafeInternals among them).

<PackageReference Include="Myriad.Core" />
<PackageReference Include="Myriad.Sdk" />
[<Generator.Fields "fields">]
type Test1 = { one: int; two: string }

Source, releases, and the changelog are on GitHub. For the mechanics, see Configuration for myriad.toml and how plugins receive settings, and How It Works for the CLI/MSBuild pipeline itself.

Further reading, from when I was building it:

Configuration

How myriad.toml works, and how plugins read it. Myriad’s configuration model is smaller than it looks from the outside: one TOML file, and two ways to tell a plugin which section of it to read. The myriad.toml file # Myriad looks for myriad.toml in the current directory by default. Each built-in plugin reads its settings from a named table in that file. For the fields plugin:

How It Works

The pipeline from annotated source to generated F#. Myriad is a small standalone CLI (Myriad.dll), driven either directly or via the MSBuild SDK, which shells out to that same CLI as a pre-build step. The pipeline is the same either way.