Proposed Stripped-Down C#
In this lesson we are going to propose a stripped-down version of C# and introduce a new operator.
We'll cover the following...
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
returntype ofIDiscreteDistribution<T>for someT. -
Just as methods that use
awaitmust be markedasync, our DSL methods must be markedprobabilistic. -
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:
-
Declaration statements must have an initializer.
-
All the locals must have unique names throughout the method.
-
Assignments can only be in declarations or as statements; no use of assignments in the middle of an expression is allowed.
-
No compound assignments, increments or decrements.
-
No
await,yield,try,throw,switch,while,do,break,continue,goto,fixed,lock,usingor labeled statements allowed. What’s left?ifandreturnstatements are fine, as well as blocks{ }. We told you we are stripping things down! -
No
lambdas, anonymous functions, or query comprehensions. -
No use of
in,out...