`with` syntax on members
isaacabraham opened this issue · 1 comments
If you want to add methods to a record, you use with and then the member keyword, followed by this and the method you want to write. This is fairly different from Rust, but once the boilerplate is done it is quite similar.
"With" isn't needed - I'm not even sure what it does in this case! You can add members just fine without it (and, AFAIK, this is the recommended way to do things).
type Foo =
{
FirstName : string
LastName : string
}
member this.Name = this.FirstName + " " + this.LastName
Note: I'm not sure using the declaration style you've been using will work though - most F#ers declare records as follows:
type Foo =
{ FirstName : string
LastName : string }
member this.Name = this.FirstName + " " + this.LastName
or as in the above sample.
Oh, that looks better. I thought I found an example with "with" in the documentation yesterday but can't remember where, and since it compiled I assumed that was the norm. Will change it to that.