An object expression creates an interface implementation directly, without first declaring a concrete implementation type. It is useful when an F# application needs an interface for C# consumption, a runtime-pluggable API, or a concise function-based contract. section 11.1.2
The compact form uses `new InterfaceName with` followed by the required members. Compared with a named implementation type, it removes boilerplate while preserving the interface contract. Annotate the value as the interface when member access is otherwise unavailable through the inferred type. section 11.1.2
Implementing an interface inline
let implementation = { new MyInterface with member _.Capitalize text = text.ToUpper() member _.Add number = number + 1 } let text = implementation.Capitalize "test" For a single-method interface, wrap a function instead of writing a named type: let makeIDisplayTime implementation = { new IDisplayTime with member _.Display date = implementation date } let shortPrinter = makeIDisplayTime (fun date -> $"It's {date.ToShortTimeString()}.") section 11.1.2 section 11.1.7
let implementation =
{ new MyInterface with #1
member this.Capitalize text = text.ToUpper() #2
member _.Add number = number + 1 #3
}
let text = implementation.Capitalize "test" #4
Use the complete inline implementation to see how object expressions replace a separately declared implementation type. section 11.1.2
let makeIDisplayTime implementation = #1
{ new IDisplayTime with
member _.Display date = implementation date #2
}
Use the function-to-interface helper to connect functional implementations with interfaces expected by C# applications. section 11.1.7

