Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Haskell's `fst` and `snd` have such a short (strange) names? [closed]

I'm new to Haskell and what really bothers me at the moment is why the people who made the libraries added functions called fst and snd instead of using (normal) names like first and second. What's wrong with the latter names?

Personally I find these abbreviations ridiculous: "Why snd? Why not sec, scnd or scd? Or why not fir, frst, ft or frt?" It just lacks style. (But again - that's a personal opinion)

like image 339
user931392 Avatar asked Dec 09 '22 15:12

user931392


1 Answers

It's clear the names were chosen to be 3 characters long whilst being as clear as possible as to the word - miss out all but the most prominent consonants. A lot of the standard functions have better/easier-to-follow names, but admittedly not all!

It's historical accident, really, what the names were, and there's not a lot we can do about it without annoying a lot of people who have got used to them and have a large code base relying on them. At least Haskell didn't call search grep!

Feel free to write first = fst and second = snd at the top of your file - it won't take long to use your preferred name, and ghc -O2 will compile them out.

first and second are actually used for something more complicated in Control.Arrow but you don't need to go that deep at this stage.

like image 67
AndrewC Avatar answered Dec 11 '22 04:12

AndrewC