Probabilistic programming is an expressive way to build stochastic models and inference procedures as separate reusable modules. We use continuations and monads, two tools from programming-language theory, to express models and inference alongside each other as ordinary code in the same general-purpose language. This way, deterministic parts of models run at full speed, so inference procedures can reason about themselves without interpretive overhead.
We use existing facilities of the language, such as rich libraries, optimizing compilers, and types, to develop realistic models whose inference performance is competitive with the state of the art. In particular, a wide range of models can be expressed using memoization, and we introduce a new, general algorithm for importance sampling with look-ahead.