Posts Tagged ‘generics’

How many methods does this interface have?

April 17, 2010 Leave a comment

How many methods are defined in this interface?

public interface IFoo
    void Bar<T>(T arg);

Read more…

The Maybe Monad in C#

December 11, 2008 6 comments

The Maybe Monad is extremely simple. It represents a value that might be there, but might not, and also provides a neat way of working with such values.

This Haskell-related page makes it pretty clear:

The Maybe monad embodies the strategy of combining a chain of computations that may each return Nothing by ending the chain early if any step produces Nothing as output. It is useful when a computation entails a sequence of steps that depend on one another, and in which some steps may fail to return a value.

Change Nothing to null and we’re talking in C#. Furthermore, it advises:
Read more…

Categories: C#, generics, monads Tags: , ,

Dynamic typing in C# 4 and Duck Generics

November 4, 2008 Leave a comment

When the dynamic typing proposal for C# came out, my feedback was basically that you can already do it in the language today:

DynamicObject Wrapper

The justification for adding dynamic is that it gets rid of a lot of ugly reflection. But delegates and indexers mean that the language already has almost enough expressiveness to hide those details entirely.

Now the proposal is getting a lot firmer and there’s a CTP available, more people are voicing their concerns. I remain pretty unconvinced of the value of it. One good point made by several people now is that it ought to be possible to use an interface to describe the set of operations that an object must support. The object wouldn’t have to genuinely implement the interface – the IDE would just use the interface’s members to offer up auto-completion in the usual way. The compiler would then simply generate dynamic calls, so the interface would be irrelevant at runtime.

Read more…

Categories: C#, dynamic, generics Tags: , ,