C#C
C#4y ago
Thinker

TSelf generic confusion [Answered]

So I'm trying to implement an IFunctor interface (so I know I'm kind of doomed from the start), but this is what I have currently:
public interface IFunctor<TSelf, T> where TSelf : IFunctor<TSelf, T>
{
    IFunctor<USelf, U> Map<USelf, U>(Func<T, U> f) where USelf : IFunctor<USelf, U>;
}

public readonly struct Maybe<T> : IFunctor<Maybe<T>, T>
{
    // ...

    IFunctor<USelf, U> IFunctor<Maybe<T>, T>.Map<USelf, U>(Func<T, U> f)
    {
        // Should actually apply the func, but just for demonstration rn
        return new Maybe<U>();
    }
}

It's ugly as hell, I know. I'm getting an error on new Maybe<U>() saying it can't implicitly convert from Maybe<U> to IFunctor<USelf, U>, except Maybe<U> should implement IFunctor<USelf, U>, right?
Was this page helpful?