Skip to content

Instantly share code, notes, and snippets.

@controlflow
Last active December 30, 2015 15:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save controlflow/7846397 to your computer and use it in GitHub Desktop.
Save controlflow/7846397 to your computer and use it in GitHub Desktop.
Boolean solver via C# overload resolution
static class BooleanSolver {
class T {
public static T operator |(T x, T y) => null;
public static T operator |(T x, F y) => null;
public static T operator &(T x, T y) => null;
public static F operator &(T x, F y) => null;
public static F operator !(T x) => null;
}
class F {
public static T operator |(F x, T y) => null;
public static F operator |(F x, F y) => null;
public static F operator &(F x, T y) => null;
public static F operator &(F x, F y) => null;
public static T operator !(F x) => null;
}
class Nil { }
class Cons<H, T> { }
static Cons<T, L> Var<L>(System.Func<T, L> f) => null;
static Cons<F, L> Var<L>(System.Func<F, L> f) => null;
static Nil IsTrue(T t) => null;
static void Main() {
// use "Specify type explicitly" context action over 'var' keyword
var result = Var(x1 => Var(x2 => Var(x3 =>
IsTrue(!x3 & !x1 & (x1 | x2 | x1) & (x2 | x3 | x2))
)));
}
}
@controlflow
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment