Search⌘ K
AI Features

Converting to Ordinary C# 7

Explore how to lower a domain-specific language for probabilistic workflows into ordinary C# 7 by rewriting code into local functions representing discrete distributions. Understand methods to handle sampling, conditions, and return statements while preserving the intended probability distributions without runtime loops.

In the previous lesson, we proposed a stripped-down DSL for probabilistic workflows. In this lesson, let’s see how we could “lower” it to ordinary C# 7 code. We will assume that we have all of the types and extension methods that we’ve developed so far.

Naive Approach

The first thing I’m going to do is describe a possible but very problematic way to do it.

We know how C# lowers methods that have yield return statements: it generates a class that ...