Skip to content

Instantly share code, notes, and snippets.

@controlflow
Last active Dec 30, 2015
Embed
What would you like to do?
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

controlflow commented Dec 7, 2013

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