Hakaru is a probabilistic programming language. A probabilistic programming language is a language specifically designed for manipulating probability distributions. These sorts of languages are great for machine learning and stochastic modeling.


This manual provides a guide for how to use Hakaru.


What is Probabilistic Programming

Probabilistic programming systems allow us to write programs which describe probability distributions, and provide mechanisms to sample and condition the distributions they represent on data. In this page, we give a sense of the sorts of problems Hakaru is great at solving, and how you would describe them in Hakaru.


Learn how to install Hakaru


Get started with this quickstart page. Where we show how to sample and condition from a small Hakaru program.


Here we go through several more involved examples of the kinds of problems Hakaru is uniquely well-suited to solve.

In particular, we describe a model for Gaussian Mixture Models and using a form of Bayesian Naives Bayes as applied to document classification.

Language Guide

The language section provides an overview of the syntax of Hakaru as well as some of the primitives in the language.

Random Primitives

These are the built-in probability distributions.

Let and Bind

This is how we can give names to subexpressions and a draw from a probability distribution.


Hakaru supports a restricted if expression

Types and Coercions

Hakaru is a simply-typed language. This section describes the types available and functions for moving between them.


Defining and using functions

Datatypes and match

Hakaru supports a few built-in datatypes, and offers functionality for taking them apart and reconstructing them.

Arrays and loops

We offer special support for arrays, and for probability distributions over arrays. We also express loops that compute sums and products.


Hakaru implements its inference algorithms predominately as program transformations. The following are the major ones our system provides.


Computing expectation of a measure


A transformation which takes a joint distribution and produces a program representing the conditional distribution.


Any Hakaru expression can be simplified, using the Maple computer-algebra system.

Metropolis Hastings

Automatically transform a measure into a transition kernel usable in a Metropolis Hastings algorithm.

Compiling to Haskell

Compiling to C


The internals section of the manual provides some insight into how Hakaru is implemented and offers guidance into how the system can be extended.







Adding a Language Feature