Last active
December 30, 2015 15:09
-
-
Save controlflow/7846397 to your computer and use it in GitHub Desktop.
Boolean solver via C# overload resolution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Original is here: http://blogs.msdn.com/b/ericlippert/archive/2007/03/28/lambda-expressions-vs-anonymous-methods-part-five.aspx