can any one explain that?
Why is functor not an interface?
If both Option and IEnumerable support the Map operation, why are we not capturing
this with an interface? Indeed, it would be nice to do so, but unfortunately, it’s not possible in
C#. To illustrate why, let’s try to define such an interface:
interface Functor<F<>, T>
{
F<R> Map<R>(Func<T, R> f);
}
public struct Option<T> : Functor<Option, T>
{
public Option<R> Map<R>(Func<T, R> f) => // ...
}
This doesn’t compile: we can’t use F<> as a type variable because unlike T, it doesn’t indicate
a type but rather a kind: a type that’s, in turn, parameterized with a generic type. And it’s not
enough for Map to return a Functor. It must return a functor of the same kind as the current
instance
If both Option and IEnumerable support the Map operation, why are we not capturing
this with an interface? Indeed, it would be nice to do so, but unfortunately, it’s not possible in
C#. To illustrate why, let’s try to define such an interface:
interface Functor<F<>, T>
{
F<R> Map<R>(Func<T, R> f);
}
public struct Option<T> : Functor<Option, T>
{
public Option<R> Map<R>(Func<T, R> f) => // ...
}
This doesn’t compile: we can’t use F<> as a type variable because unlike T, it doesn’t indicate
a type but rather a kind: a type that’s, in turn, parameterized with a generic type. And it’s not
enough for Map to return a Functor. It must return a functor of the same kind as the current
instance