...

/

Proposed Stripped-Down C#

Proposed Stripped-Down C#

In this lesson we are going to propose a stripped-down version of C# and introduce a new operator.

Stripped Down C#

Without further ado, here is our proposed stripped-down C# that could be a domain-specific language (DSL) for probabilistic workflows; as we’ll see, it is quite similar to both enumerator blocks from C# 2, and async/await from C# 5.

Workflow

  • The workflow must be a function with a return type of IDiscreteDistribution<T> for some T.

  • Just as methods that use await must be marked async, our DSL methods must be marked probabilistic.

  • The function has an ordinary function body: a block of statements.

We are using C# 5 asynchronous workflows as an example of how to add a new mechanism to C#. The statements and the expressions in a probabilistic method are restricted as follows:

  1. Declaration statements must have an initializer.

  2. All the locals must have unique names throughout the method.

  3. Assignments can only be in declarations or as statements; no use of assignments in the middle of an expression is allowed.

  4. No compound assignments, increments or decrements.

  5. No await, yield, try, throw, switch, while, do, break, continue, goto, fixed, lock, using or labeled statements allowed. What’s left? if and return statements are fine, as well as blocks { }. We told you we are stripping things down!

  6. No lambdas, anonymous functions, or query comprehensions.

  7. No use of in, out or ...