prodigy.pgcl.ast¶
AST¶
All data types to represent a pGCL program.
Note
For our AST types, most “sum types” have a normal Python superclass (e.g. TypeClass for types), but also a Union type (e.g. Type).
Prefer using the Union type, as it allows for exhaustiveness checking by mypy.
In some rare cases, it’s necessary to tell mypy that an object of a superclass type is actually in the respective union.
Use cast methods, e.g. InstrClass.cast() to go from InstrClass to Instr.
Also note that isinstance checks must be done against the superclasses, because Python’s Union does not yet work with isinstance.
Program¶
Types¶
Declarations¶
Expressions¶
In the AST, a bunch of different things that look like program expressions are lumped together. Formally, let a state \(\sigma \in \Sigma\) consists of a bunch of values for each variable, and be represented by a function of type \(\sigma : \text{Var} \to \text{Value}\).
First, there are state expressions that, given a state \(\sigma\), compute
some value to be used later in the program itself: \(\Sigma \to
\text{Value}\). There are two types of expressions we call monadic expressions:
UniformExpr and CategoricalExpr. They map a state to a
distribution of values: \(\Sigma \to \text{Dist}[\Sigma]\). And
expectations are also expressed using Expr, but they are actually a
mapping of states to expected values: \(\Sigma \to \mathbb{R}\).
Instructions¶
Superclasses¶
These are only used for use with isinstance. Otherwise use corresponding Union types instead.