Problems encountered during Sturct packing

Source: Internet
Author: User

Problems encountered during Sturct packing

An Object will generate a temporary variable in the stack space during unpacking. Therefore, it is better to declare all content as readonly when using Struct.

[<Struct>] type Point = val mutable X: double val mutable Y: double member x. change (a, B) = x. X <-a x. Y <-B override x. toString () = sprintf "% A" x. X x. ylet mutable p = Point (X = 1 ., Y = 1 .) p. toString () // out: 1.0 1.0p.Change (3 ., 2 .) p. toString () // out: 3.0 2.0let o = p:> objo. toString () // out: 3.0 2.0 (o:?> Point). Change (5., 5.) o. ToString () // no change out: 3.0 2.0

F # The generated struct instance is read-only by default. That is to say, without mutable, Change does not work at all. Better protection.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.