Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

F# Interface Implementation

Tags:

interface

f#

Let say I have this interface in C# and want to implement it in F#

public interface IBatch
{
    System.Data.IDbConnection Connection { get; set; }
}

I wish to implement the interface in F# but cant figure out the correct syntax. I have something like this:

type public Batch = 
    interface IBatch with
        member f.Connection 
            with get() = new Devart.Data.Oracle.OracleConnection()
            and set value = ()

The error I'm getting is:

This expression was expected to have type IDbConnection but here has type Devart.Data.Oracle.OracleConnection

like image 313
Filip Avatar asked Oct 22 '13 07:10

Filip


1 Answers

F# does not implement implicit downcasting like C# does, you need to have

type public Batch = 
    interface IBatch with
        member f.Connection 
            with get() = new Devart.Data.Oracle.OracleConnection() :> System.Data.IDbConnection
            and set value = ()
like image 200
John Palmer Avatar answered Sep 21 '22 02:09

John Palmer