<double post>

By on 12/24/2010 2:50 PM ()

I suspect that this is by design. F#'s design for extension members is fundamentally different from C#'s in some ways. Specifically, extensions in F# are defined as if they were members on the original type, whereas extensions in C# are special kinds of static methods. One limitation that this difference causes is that given a generic type (such as seq<'a>), in C# you can define extension methods on constructed generic types (such as adding a Sum method to seq<int>), whereas in F# you can only add extensions to the open generic type itself (that is, to seq<'a>). Your issue appears to be similar to this: since you can't add methods to the definition of an enum, you can't add them to an extension either.

Although this limitation may be aggravating in your case, keep in mind that the F# approach also has several benefits compared to the C# approach, such as the ability to add extension properties and static members.

By on 12/24/2010 2:50 PM ()

Thanks. I'm hoping that it's a decision that they'll rethink in the future; as far as I'm aware, it should be possible to have [b]both[/b] C#- and F#-style extensions/augmentations in F#. There doesn't seem to be a technical reason behind this restriction.

In the meantime, I guess I'll be compiling C# extensions to get the language syntax I want in F# :/. Messy.

By on 12/27/2010 3:07 AM ()

I also would love to know the reason for this restriction. Maybe it's a bug? BTW, try writing extension method in C# and import the dll. We'll see who has the last laugh.

By on 12/24/2010 12:57 PM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper