Introducing IEvaluable<T, R>

Last year, I was watching a recorded session from NDC2013. It was “Faking homoiconicity in C# with graphs” from Mark Seeman. I really liked his approach in refactoring a transaction script into some smaller testable pieces. Although his motivation was imho increasing testability, I decided to not stop there but try to bring something up that is generally useful. During the same time I was wathcing lots of videos related to functional programming in Haskell and F#. The most interesting part for me was to understand what a monad is. I was lucky, since Eric Lippert decided to write a whole bunch of posts on this topic. His posts really helped me a lot in understanding monads. This new knowledge combined with the information of Mark’s session finally did the trick for me. I developed a simple new generic interface with two type parameters. Here it is:

public interface IEvaluable<in T, out R>
    R Evaluate(T param);

The signature almost says it. An object implementing IEvaluable<T, R> must provide a method that takes a parameter of type T and returns a result of type R. It is essentially an object version of a Func<T, R> delegate.

In the upcoming series of posts I will try to illustrate the use cases, in which this interface comes in handy, implement a whole bunch of LINQ-like operators upon it and also try to prove monadic and comonadic laws on it (though I hope someone with a strong functional background will give me feedback and improvements or corrections on it).

Stay tuned. This will be a lot of fun!


Posts in this series:

Projections on IEvaluable<T, R>

Leave a Reply

Your email address will not be published. Required fields are marked *