Using a Bound Interface in F #

I'm trying to use a C # library in F #, so this would be a very specific case. I am using Servicestack with F #. Now I am trying to connect a class with an interface using the method

RegisterAutoWiredAs<T,'TAs>()

      

signature. Here "T has a limitation that it must implement" TA ". It works fine in C # code.

But F # has a limitation in using the interface.

let f:IFoo = Foo() // will give type error
let fi:IFoo - Foo() :> IFoo // will work

      

Here Foo has implemented IFoo. So this part is different from the C # equivalent. Now type error appears above the signature, if I like it

container.RegisterAutoWiredAs<Foo,IFoo>()

      

And now you need to do casting when setting the parameter.

Here is a line from the original project I am trying to run. Everything in this code works differently than this part, and also, unfortunately, other equivalent methods fail as well.

And here is the error I am getting in this project

This expression was expected to be of type 'MemoryChatHistory', but there is type 'IChatHistory' here

+3


source to share


1 answer


F # does not support implicit interface implementations.

I think you can get around this in this case by making IChatHistory an abstract class rather than an interface (using an attribute [<AbstractClass>]

).

EDIT:

No, I had the opportunity to play with him today. I think it is not possible to directly call this method with these type parameters from F #. See this question



How to convert parameter constraint of type `T: U` from C # to F #?

for a more detailed discussion.

You might be able to get around this by using reflection to call the method.

+1


source







All Articles