Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the history of the variable names x and xs? [closed]

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'.

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.

like image 219
jsau Avatar asked Jun 07 '11 15:06

jsau


People also ask

What is Xs in functional programming?

(x:xs) just means a single x is attached as the head of a list of xs (essentially, sort of conveying the message that it is a list containing similar x elements).

Why is Xs used in Haskell?

x:xs represent a list which x is the first element (head) and xs is the rest of the list (tail). This pattern is commonly found in pattern matching of a function that has list as argument along with [] (empty list).


2 Answers

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.

like image 78
mipadi Avatar answered Sep 23 '22 08:09

mipadi


We can take the origins of x back much further, of course :-) François Viète (1540-1603) produced a book titled In artem analyticem isagoge (“Introduction to the Analytic Art”), which was the first work that systematically used letters to represent numbers.

Edit: Porges, below, points me to the really cool A History of Mathematical Notations by Cajori. To my pleasant surprise, the entire work is available online: http://archive.org/details/historyofmathema031756mbp

like image 27
sclv Avatar answered Sep 24 '22 08:09

sclv