Surprising compilation error when trying to implement an interface using object expressions.
Repro Steps
type IInterface =
abstract Function : (int32 * int32) -> unit
{ new IInterface with
member this.Function (i, j) = ()
}
Expected
Compilation without errors like this:
type IInterface =
abstract Function : int32 -> unit
{ new IInterface'with
member this.Function (i) = ()
}
Actual
The compilation error is:
FS0768: The member 'Function' does not accept the correct number of arguments, 1 arguments are expected
Severity
- Confusing for newcomers.
- Cumbersome to remember.
- But easy workaround.
Version
- F# 4.0 (FSharp.Core, 4.4.0.0)
- F# Compiler version 14.0.23413.0
- .NET Runtime, Framwork 4.6
- Windows 10
- Visual Studio Community 2015 version 14.0.2513.00 Update 2
Workaround
Surround the error producing parameter with additional brackets:
type IInterface =
abstract Function : (int32 * int32) -> unit
{ new IInterface with
member this.Function ((i, j)) = ()
}