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.
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
x
is the european transcription of the arabic word شيء (pronounce 'chi', or 'chaï'. or 'tchi', depending on the accent). This word means 'thing', or 'something' and was used by first arab and iranian mathematicians as a symbol to designate an unknown or unfixed value in a mathematical expression.Back to these times, 'x' might have been considered by translators and european mathematicians as the closest approximation to this symbol of the unknown.
x
is a common variable name in mathematics.xs
is the plural form ofx
(get it?). In list pattern matching,x
is one element, andxs
is (generally) several.