变量名 x 和 xs 的历史是什么? [英] What is the history of the variable names x and xs?

查看:19
本文介绍了变量名 x 和 xs 的历史是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习一些 Haskell,我在敬畏和困惑之间交替.对我来说,真正让我感到疏远的事情之一是模式匹配习惯用法 (x:xs).这些变量名从何而来?它们可以是任何东西——(kernel:cob)(spam:eggs)(稍微倾斜我的手),或者——最明智地,在我看来,(h:t),代表头"和尾".

I'm trying to pick up a bit of Haskell, and I'm alternating between awe and befuddlement. One of the really alienating things for me, trivial as this may seem, is the pattern matching idiom (x:xs). Where do those variable names come from? They could be anything -- (kernel:cob), (spam:eggs) (tipping my hand a bit), or -- most sensibly, to my mind, (h:t), standing for 'head' and 'tail'.

我认为 x 前缀对于表明两个项目来自同一个列表很有用,所以 (xh:xt) 甚至只是 (x:xt) 如果你觉得特别简洁.但是为什么s?这是什么意思?它从哪里来的?我觉得,此刻,知道会帮助我应对我的困惑.

I suppose the x prefix is useful for indicating that both items come from the same list, so then (xh:xt) or even just (x:xt) if you're feeling especially terse. But why s? What does it mean? Where did it come from? I feel, at the moment, that knowing would help me cope with my confusion.

也许我的想法是错误的;请随时告诉我.

Perhaps I am thinking about this in the wrong way; please feel free to tell me so.

推荐答案

x 是数学中常见的变量名.xsx 的复数形式(明白了吗?).在列表模式匹配中,x 是一个元素,xs 是(一般)几个.

x is a common variable name in mathematics. xs is the plural form of x (get it?). In list pattern matching, x is one element, and xs is (generally) several.

这篇关于变量名 x 和 xs 的历史是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆