// csharp
public interface FromCSharp
{
void F<Enumerable>(Enumerable source)
where Enumerable : System.Collections.IEnumerable;
}
// fsharp
type C<'T>() =
interface FromCSharp with
member __.F<'Enumerable
when 'Enumerable :> System.Collections.IEnumerable
> (e:'Enumerable) : unit = ()
The following more complex example doesn't (i.e. it introduces another generic type at the interface level):
// csharp
public interface FromCSharp<T>
{
void F<Enumerable>(Enumerable source)
where Enumerable : System.Collections.Generic.IEnumerable<T>;
}
// fsharp
type C<'T>() =
interface FromCSharp<'T> with
member __.F<'Enumerable
when 'Enumerable :> System.Collections.Generic.IEnumerable<'T>
> (e:'Enumerable) : unit = ()
It fails with the following compliation error:
The member 'F<'Enumerable when 'Enumerable :> Collections.Generic.IEnumerable<'T>> : #Collections.Generic.IEnumerable<'T> -> unit' does not have the correct type to override the corresponding abstract method.
If you define the interface in fsharp it does work (even in a different assembly):
type FromFSharp<'T> =
abstract F<'Enumerable
when 'Enumerable :> System.Collections.Generic.IEnumerable<'T>> : 'Enumerable -> unit
type C<'T>() =
interface FromFSharp<'T> with
member __.F<'Enumerable
when 'Enumerable :> System.Collections.Generic.IEnumerable<'T>
> (e:'Enumerable) : unit = ()
No known work around, other than to define all interfaces in fsharp, which is obviously not always an option.
The following works:
The following more complex example doesn't (i.e. it introduces another generic type at the interface level):
It fails with the following compliation error:
If you define the interface in fsharp it does work (even in a different assembly):
No known work around, other than to define all interfaces in fsharp, which is obviously not always an option.