views:

33

answers:

1

Hi,

Do you see a way to specify that my result type have to be MonadType< arg type > within this interface ?

interface IMonad<MonadType>  //  where MonadType : GenricType<>
{
    MonadType<T1> unit<T1>(T1 t)
    Func<MonadType<T1>, MonadType<T2>> map<T1, T2>(Func<T1, T2> f);
}

I get as an error : The type parameter 'MonadType' cannot be used with type arguments

A: 

No, you can't do this with .NET generics. What you want to do is to specify that the MonadType type parameter must itself have one generic parameter; the .NET type system can't represent that constraint.

Here's one approach to faking generic monads in C#: http://sandersn.com/blog//index.php/2010/04/23/faking-type-classes-in-c

Tim Robinson