加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

为什么Scala元组的索引为1?

发布时间:2020-12-16 09:45:30 所属栏目:安全 来源:网络整理
导读:“Scala中的编程”解释说,元组’ _N numbers are one-based,instead of zero-based,because starting with 1 is a tradition set by other languages with statically typed tuples such as Haskell and ML 但这几乎不能称之为解释。 为什么元组在Haskell和
“Scala中的编程”解释说,元组’

_N numbers are one-based,instead of zero-based,because starting with 1 is
a tradition set by other languages
with statically typed tuples such as
Haskell and ML

但这几乎不能称之为解释。

为什么元组在Haskell和ML中定义为1,首先呢?
在基于1的索引元组中不存在任何数学/编程的优势,而不是基于0的索引元组?

谢谢,
Ori

解决方法

我猜_1,_2等是“第一”,“第二”等等的缩写。 (例如,fst和snd历来被用于访问元组的左侧和右侧部分)。另一方面,数组中的索引是偏移量,第一个元素通常在偏移量0。

Are there any mathematical/programming benefits in having 1-based indexed tuples and not 0-based?

不管这些元素是不是程序地访问。 (如果我是一个整数,你不能做_i)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读