hubFS: THE place for F#

. . . are you on The Hub?
Welcome to hubFS: THE place for F# Sign in | Join | Help
in Search

Change to Object Expressions in 1.9.6.16

Last post 05-21-2009, 7:29 by RayV. 2 replies.
Sort Posts: Previous Next
  •  05-21-2009, 4:46 10412

    Change to Object Expressions in 1.9.6.16

    I am confused about a change made to object expressions in 1.9.6.16.

    Previously, we were able to differentiate between similar record types like so:

    type A = { Foo : int }
    type B = { Foo : int }
    let a = { new A with Foo = 1 }


    With 1.9.6.16, this generates a warning:

    warning FS0035: This construct is deprecated: This form of object expression is deprecated. Use 'member this.MemberName ... = ...' to define member implementations in object expressions.

    But if I rewrite my example as:

    type A = { Foo : int }
    type B = { Foo : int }
    let a = { new A with member this.Foo = 1 }


    I get the seemingly contradictory error:

    error FS0191: Only simple bindings of the form 'id = expr' can be used in construction expressions

    Am I doing something wrong? Can anyone offer me some advice? Thanks!
  •  05-21-2009, 7:19 10417 in reply to 10412

    Re: Change to Object Expressions in 1.9.6.16

    Can't answer those specific warnings or errors but you can accomplish the same assignment with either of these two forms. And it's less typing...

    let a = { Foo = 1 } : A
    let a:A = { Foo = 1 }

  •  05-21-2009, 7:29 10418 in reply to 10417

    Re: Change to Object Expressions in 1.9.6.16

    logicalmind:
    Can't answer those specific warnings or errors but you can accomplish the same assignment with either of these two forms.


    That was very helpful! Thanks so much! =)
View as RSS news feed in XML
Powered by Community Server, by Telligent Systems