作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用两者的优点和缺点是什么
type Complex =
{
real: float;
imag: float;
}
type Complex =
Complex of
real: float *
imag: float
最佳答案
使用辅助函数,您可以从两种方法中获得相同的结果。
记录
type ComplexRec =
{
real: float
imag: float
}
// Conciseness
let buildRec(r,i) =
{ real = r ; imag = i }
let c = buildRec(1.,5.)
// Built-in field acces
c.imag
type ComplexUnion =
Complex of
real: float * imag: float
// Built-in conciseness
let c = Complex(1.,5.)
// Get field - Could be implemented as members for a more OO feel
let getImag = function
Complex(_,i) -> i
getImag c
关于f# - 记录 vs 单例歧视工会,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43251264/
我是一名优秀的程序员,十分优秀!