Coffeehouse Thread

4 posts

F# Object Expressions for C#

Back to Forum: Coffeehouse
  • User profile image

    F# Object Expressions

    I even commented about it a year or two ago of how I wanted to be able to create an anonymous object of an Interface. I want it implemented for C# also!  Maybe we can hope for it for C# 6.0.

    type IFirst =
        abstract F : unit -> unit
        abstract G : unit -> unit
    type ISecond =
        inherit IFirst
        abstract H : unit -> unit
        abstract J : unit -> unit
    let implementer() = {
        new ISecond with
            member this.H() = ()
            member this.J() = ()
        interface IFirst with
            member this.F() = ()
            member this.G() = ()

  • User profile image

    Don Syme will say: Just use F# !

  • User profile image

    @felix9:Hehe I guess.  I am using F# already on my own, but just about to start using it for my work projects.
    Regardless, it would be nice to have it for the C# language also because it'd be neat.

  • User profile image

    Do you have a compelling use-case for it?

    If I had to pick something from F# then Object Expressions would definitely not top the list. More like discriminated unions or the Scala equivalent. But even without those it's entirely possible to survive, using polymorphism and the visitor design pattern instead of pattern matching.

Comments closed

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.