Coffeehouse Thread

4 posts

F# Object Expressions for C#

Back to Forum: Coffeehouse
  • stun

    F# Object Expressions http://msdn.microsoft.com/en-us/library/dd233237.aspx

    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() = ()
    }

  • felix9

    Don Syme will say: Just use F# !

  • stun

    @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.

  • exoteric

    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.