OCaml中的记录和元组有什么区别

OCaml中的记录和元组有什么区别

本文介绍了OCaml中的记录和元组有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

记录和元组之间是否存在不仅语法上的差异?

Is there any difference between records and tuples that is not just a syntactic difference ?

在性能上有区别吗?

元组和记录的实现是否相同?

Is the implementation the same for tuples and records ?

您有可以使用元组完成但不能通过记录完成的事情的示例吗?相反)?

Do you have examples of things that can be done using tuples but not with records (andconversely) ?

推荐答案

仅浮点记录或数组中的浮点字段未装箱存储,而这种优化不适用于元组.如果要存储很多浮点数且仅存储浮点数,则使用记录很重要-并且可以通过拆分混合的浮点数/其他数据结构以拥有仅内部浮点数的记录来获得收益.

Floats fields in float-only records or arrays are stored unboxed, while no such optimization applies to tuples. If you are storing a lot of floats and only floats, it is important to use records -- and you can gain by splitting a mixed float/other datastructure to have an internal float-only record.

其他差异在类型级别上,并且已经由Andreas进行了描述-记录是生成的,而元组已经存在并且具有结构语义.如果要使用具有多态访问器的结构记录,则可以使用对象类型.

The other differences are at the type level, and were already described by Andreas -- records are generative while tuples pre-exist and have a structural semantics. If you want structural records with polymorphic accessors, you can use object types.

这篇关于OCaml中的记录和元组有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 10:51