A YouTube video I was watching explained the differences between Imperative and Functional programming by demonstrating how the numbers from 1
to 10
are summed up in Java and in Haskell respectively.
In Java, you must explicitly state each step and assign the result of each step to a variable - something like the following
int total = 0;
for (int i = 1; i <= 10; i++){
total = total + i;
}
return total;
In Haskell, you can simply say:
sum(1..10)
My question is: There obviously is something going on in the background of a Functional language, and that something must be some sort of Imperative process.
It seems like Functional Languages are really just some sort of Imperative-Language APIs.
For example, I can create part of a functional language by defining a method sum(int start, int end)
in Java. Did I really create a new type of language right there, or did I just define a set of Imperative method calls that hide imperative instructions from you?
I hope it's clear what I am struggling to understand.