• Records can be used as part of standard pattern matching; classes cannot without resorting to active patterns or when guards.
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 (and discriminated unions) get structural comparison and equality semantics for free.
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
JavaScript Functional Programming
JavaScript Functional ProgrammingJavaScript 函数式编程Lambda function
函数式编程 RxJS Ramda js 函数式编程 !== 函数编程