Challenges for Improving Imperative Probabilistic Workflows
We'll cover the following...
In the previous lesson, we gave you several challenges for improving our DSL for imperative probabilistic workflows.
Compiler Writer’s Approach
Let’s solve a few puzzles:
Question One: You are walking down the street when you see a can of gasoline, some matches, a house on fire, a wrench, a fire hose, and a fire hydrant. You consider the house being on fire to be problematic, so what do you do?
Question Two: You are walking down the street when you see a can of gasoline, some matches, a house not on fire, a wrench, a fire hose, and a fire hydrant. What do you do?
That’s how compiler writers approach problems. We know how to do lowerings in a very simplified version of probabilistic C#; to lower more complicated forms, we keep on applying the “lower it to a previously solved problem” technique:
-
gotois straightforward: you evaluate the “statement method” that is the statement you’re going to. -
Once you have
gotoandif, it is straightforward to implementdo,while,breakandcontinue; reduce those to combinations ofifandgoto, which are previously solved problems. -
forloops are just an irritatingly complicated version ofwhile, which is an already solved problem. -
Implementing
throwandtryis tricky because it is a non-local goto. Throughout the history of C#, methods involving various combinations oftry,catch,finally,throw,yield return,yield breakandawaithad restrictions placed on them in C# because of the complexities involved in handling non-local branching in complex workflows. The details of how a compiler team might go about dealing with the combination ofthrowandsamplein a probabilistic workflow are beyond the scope of this course; if this subject interests you, consider doing research on how the C# compiler implements asynchronous workflows that can throw. -
We have not solved the problem for
try, which means that we’re blocked onforeach,lockandusing, all of which are syntactic sugars fortry.
To allow the sample operator in more places, again, reduce the problem to previously solved problems. For example: