By any chance, is there a "naked type constraint" on CreateInstance (i.e. is the signature actually

1
CreateInstance<S,I>() where S : I

)? If so, it's unfortunately not possible to call the method in F# unless S and I are the exact same type.

By on 12/7/2010 1:45 PM ()

There is a "where" clause on this method. S is equal to the service being called and I equals the interface the service implements.

That answers why it compiles when I change both to one value.

Are there any workarounds?

By on 12/8/2010 6:57 AM ()

There is a "where" clause on this method. S is equal to the service being called and I equals the interface the service implements.

That answers why it compiles when I change both to one value.

Are there any workarounds?

Sadly, there's no good workaround. One option would be to write a C# shim which creates and wraps that object (but the C# object you expose would need not to have multiple type parameters which have a subtype relationship). Another option would be to create the object in F# using reflection (and store it as a variable of type obj) and then call any methods on it reflectively as well (possibly using the F# (?) operator to simplify the syntax).

By on 12/8/2010 7:50 AM ()

Assuming that, in this case, CreateService<S,S> returns the same object as CreateService<S,I> (does it?), why not just call CreateService<S,S> :> I e.g. call it and then upcast to the target interface?

By on 12/8/2010 8:03 AM ()
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