Skip to content

Instantly share code, notes, and snippets.

@ufcpp
Created February 6, 2015 17:50
Show Gist options
  • Select an option

  • Save ufcpp/ff2b41792a320b64b89a to your computer and use it in GitHub Desktop.

Select an option

Save ufcpp/ff2b41792a320b64b89a to your computer and use it in GitHub Desktop.
decomposition of data types
// composition
var expr = Add(Mult(Const(2), X()), Const(1));
// decomposition
switch (expr)
{
case Add(Mult(var a, var x), var b): ...;
}
abstract class Expr;
class X() : Expr;
class Const(double Value) : Expr;
class Add(Expr Left, Expr Right) : Expr;
class Mult(Expr Left, Expr Right) : Expr;
class Neg(Expr Value) : Expr;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment