Is it possible to define a generic extension method in F#?

If I understand your question correctly, the answer is no Section 8.12.1 of the spec (Imported C# Extensions Members) includes this text: C#-defined extension members are made available to F# code in environments where the C#-authored assembly is referenced and an open declaration of the corresponding namespace is in effect. However, some limitations apply, notably C# extension members whose “this� Parameter is a variable type are not made available to F# code in this version of F C# extension members whose “this�

Parameter is an array type are not made available to F# code in this version of F This explains why some extension methods from C# will work (e.g. Those in System. Linq), while the one that you are attempting to use will not Furthermore, native F# extension methods can only be defined as if they were placed on actual type definitions. In particular, you can't define an F# extension method on a closed generic type (e.

G IEnumerable.

If I understand your question correctly, the answer is no. Section 8.12.1 of the spec (Imported C# Extensions Members) includes this text: C#-defined extension members are made available to F# code in environments where the C#-authored assembly is referenced and an open declaration of the corresponding namespace is in effect. However, some limitations apply, notably C# extension members whose “this�

Parameter is a variable type are not made available to F# code in this version of F# C# extension members whose “this� Parameter is an array type are not made available to F# code in this version of F# This explains why some extension methods from C# will work (e.g. Those in System. Linq), while the one that you are attempting to use will not.

Furthermore, native F# extension methods can only be defined as if they were placed on actual type definitions.In particular, you can't define an F# extension method on a closed generic type (e.g. IEnumerable) nor can you define an extension method on a generic type variable.

Thank you for the answer! – Vagif Abilov Aug 2 '10 at 8:29.

As kvb mentioned, it's not possible in F# 2.0. In this particular case I'd wrap Rhino. Mocks fluent interface to make it more idiomatic in F#, e.g. : let mstub f target = RhinoMocksExtensions.

Stub(target, Function(f)) let mreturn value (options: IMethodOptions) = options. Return value let service = MockRepository.GenerateMock() service |> mstub (fun s -> s. Compare(1,2)) |> mreturn 1 |> ignore What's fluent in one language is not necessarily fluent in another.

(sorry for the plug but I really think it's relevant here).

Marurcio, Thank you for the explanation. Yes, I also came to the same conclusion that such extensions that are quite useful in C# wouldn't bring that much value to F#, and there are other (and better) ways of expressing this in F#. – Vagif Abilov Aug 2 '10 at 8:32.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions


Thank You!
send