f# – 记录与单一案例歧视联盟
发布时间:2020-12-14 04:53:43 所属栏目:百科 来源:网络整理
导读:什么是Pro和Con使用的 type Complex = { real: float; imag: float; } 要么 type Complex = Complex of real: float * imag: float 我对不同情况下的可读性和处理特别感兴趣. 并且在较小程度上,表现. 解决方法 使用辅助函数可以从两种方法中获得相同的结果.
什么是Pro和Con使用的
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 我想联盟类型的(频繁)分解会影响性能,但我不是这方面的专家. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |