Tech Off Post

Single Post Permalink

View Thread: Functional Style Boolean Logic in C#
  • User profile image
    AceHack

    Are their any issues with this approach?  I'm also trying to follow a very function first style so am I doing that correctly.  Also can anyone see a way to make this shorter.  For instance I hate having to repeat the signatures twice every time.  var will not work here.  I'm trying to do something similar to what Erik did here. 

    http://channel9.msdn.com/shows/Going+Deep/C9-Lectures-Dr-Erik-Meijer-Functional-Programming-Fundamentals-Chapter-4-of-13/ 

    Thanks.

     

        abstract class Bool
        {
            public static readonly Bool True = new True();
            public static readonly Bool False = new False();
    
            public static readonly Func<Bool, Bool> Not =
                new Func<Bool, Bool>(a => a is True ? False : True );
    
            public static readonly Func<Bool, Func<Bool, Bool>> And =
                new Func<Bool, Func<Bool, Bool>>(a => b => a is True ? b : a);
        }
        class True : Bool {}
        class False : Bool {}