Ray's playground

 

Functional Programming(Chapter 3 of Programming F#)

  You can easily create properties and methods in F#, so why use a record? Records offer several distinct advantages over traditional object-oriented data structures:
  • Type inference can infer a record’s type. No need for superfluous type annotations.
  • Record fields are immutable by default, whereas class types offer no safety guarantee.
  • Records cannot be inherited, giving a future guarantee of safety.

  • Records can be used as part of standard pattern matching; classes cannot without resorting to active patterns or when guards.

  • Records (and discriminated unions) get structural comparison and equality semantics for free.

posted on 2010-05-25 20:57  Ray Z  阅读(205)  评论(0编辑  收藏  举报

导航