“Haskell” – is a (purely) functional programming language. 👾
In “imperative” languages – you get things done by giving a sequence of tasks (№№ 0️⃣, 1️⃣, 2️⃣, 3️⃣, …) to the Computer 🤖, – and then – it executes them … While executing – it can change “state”; for instance: you set «“a
” = “5
”», – and then – do some stuff; and then – reset it, to something else … You have control flow structures, for doing some action several times!
In purely “functional” programming – you don’t tell (to the Computer 🤖) what to do, but rather – what the stuff is:
1
» – to that number;You express that – in the form of functions! … You (also) can’t set a variable to something, and then – reset it (to something else) later: if you say «The “a
” – is “5
”» – you can’t say «It’s something else!» later, because you have said it was “5
” … What are you? – Some kind of liar? 💔
So, in purely functional languages, – a function – has no “side effects” ✨; the only thing it can do – is to calculate 🧮 – and – return something (as a “result”)…
At first, this – seems (kind of) “limiting”, but – has some very nice consequences: if a function is being called twice (with the same parameters) – it’s guaranteed – to return the same result! …
That’s – called “referential transparency”; and not only does it allow the Compiler 🤖 to reason about the Program’s behavior, but – it (also) allows you to easily deduce (and even prove) that: «The function – is correct!»; and then – build more complex functions: by “gluing” “simple” functions – together! 🧱
“Haskell” – is “lazy”; that – means that (unless – specifically told, otherwise): “Haskell” – won’t neither execute functions, nor calculate things – until – it’s really forced, to show you the result! 💤
That – goes well with “referential transparency”; and – it allows you 🎓 to think (of programs) as of series of “transformations” on data. It (also) allows “cool” things, – such, as infinite data structures. ♾
Say – you have:
xs = [1, 2, 3, 4, 5, 6, 7, 8]
»;doubleMe
”, – multiplying every element by “2
”, and (then) returning a new list.If we wanted to multiply our list by “8
”:
If we do a «doubleMe(doubleMe(doubleMe(xs)))
», – it would (probably):
Then – it would pass (through the list) for another two times, and – return the result.
Calling «doubleMe
» on a list (without forcing it, to show you the result) – ends up in the Program (sort of) “telling” you: «Yeah, yeah! … I’ll do it, later». But once you want to see the result, – then:
doubleMe
” – tells to the second one: «It _wants_ the result; now!»; 1️⃣ 🤜 🖐 2️⃣ 3️⃣1
” (which is a “2
”); 1️⃣ 2️⃣ 🖐 🤛 3️⃣4
” (to the first one); 1️⃣ 🖐 🤛 2️⃣ 3️⃣8
”…». 🤖 🤲 🤛 1️⃣ 2️⃣ 3️⃣So – it does only one pass through the list, and only when you “really” need it! … That way, when you want something from a “lazy” language – you can (just) take some initial data, and efficiently transform (and mend) it; so – it resembles what you want, at the end.
“Haskell” – is statically typed. When you compile your program – the Compiler 🤖 knows:
That – means that: a lot of possible errors are caught at compile time 🤏: if you try to add (together) a “number” and a “string” – the Compiler 🤖 will “whine” at you! 👋 …
“Haskell” – uses a type system, which has “type inference”. That – means that: you don’t have to explicitly label every piece of “code” with a type – because the “type system” can (intelligently ✨) figure out a lot, about it. 🤖
If you say: «“a
” = 5 + 4
» – you don’t need to tell “Haskell”, that «“a
” – is a number»; – it can figure that out, by itself ! 🎲 👁🗨
Type inference (also) allows your code to be more “general”: 🎓 if a function (you make) takes two parameters (and – adds them, together), and you don’t (explicitly) state their type – the function will work on any two parameters, which act like numbers. 🔢
“Haskell” – is elegant and concise 🎩 … Because it uses a lot of “high level” concepts – “Haskell” programs are (usually) shorter, than their imperative equivalents. And, shorter programs – are easier to maintain 🖇 (than longer ones); and have less “bugs”. 🐛
“Haskell” – was made by some really smart guys, with “Ph. D.” 🎓
Work (on “Haskell”) – began in 1987 (when a committee of researchers got together, to design a nice language).
In 2003 – the «“Haskell” report» was published (which defines a stable version, of the language).