Is functional programming so related to mathematics because much of the functional programming is depicted with mathematical notions? Is it a MUST to have a strong base of
maths to learn & understand functional programming for a programmer with a imperative background?

This question came from our site for professional and enthusiast programmers.

1

Is this question correctly tagged with mathematica or should it be math?
–
Sjoerd C. de VriesMar 21 '11 at 7:14

Here and here are two very similar questions. I don't think you have to have a 'strong base' in math but you need a fairly good understanding of it's principles from some point of view. Geometry helps me the most with memory mapping, but I rarely think of the numbers as such much anymore. Math is (can be) VERY useful though.
–
Garet ClabornMar 21 '11 at 9:14

5 Answers
5

All programming is related to mathematics. Indeed many universities still place their computer science programs under the purview of the mathematics department.

As for learning functional programming, you do not need to have a strong base in mathematics to learn it. I've learnt three different functional languages now to reasonable proficiency (Haskell, Erlang, Clojure) and my own maths skills are extremely weak. Haskell's community can, indeed, get a little bit annoying in its maths-focused way of speaking about things, but Erlang and Clojure both are very pragmatic functional programming languages that are not that hard to pick up because the tutorial information is written, seemingly, for programmers, not hard-core maths geeks. That being said, despite my handicap in maths I did pick up Haskell, so it's not impossible.

The real difficulty I've found in picking up declarative programming languages in general (of which functional is a subset) is giving up that urge to be in control; to tell the computer what to do. It takes some getting used to.

The short answer is: Yes, because everything with a certain degree of formalization (such as programming languages) is strongly related to mathematics, for varying degrees of mathematics.

But, using a programming language does not strictly require familiarity with mathematics, for example theroetical foundations of languages. You don't have to know what a context free language is and what laws and property such a language has in order to use one. Likewise, you don't have to be a Germanist or Romanist to speak german or french.

The "mathematical" notation is not a common property of functional languages. Scala and all Lisp based languages have very different syntaxes compared to Haskell.

You are writing what the program is supposed to do in a form of equations defining new values (note: not variables) as functions of previously defined values. You also define the functions as relations. It is really quite similar to the way mathematical theorems are written.

I can understand mathematical functions better than the weird synatx of haskell and others. Do you have any link that relates math steps to syntax of any functional language.
–
RainDoctorJan 25 at 7:35

IMO Mathematica, as an example of a language in which you can use functional programming, does not require a strong background in math. In fact, I don't think I encountered anything like functional programming during my basic math education. I started Mathematica programming doing C-style, and discovered functional programming only years later. I don't think the basic functional programming constructs like Map, Apply, NestList, etc require any math background at all.

not really. functional programming is just a methodology, but it had its base in lambda calculus and stuff like that.

Closures are a (small) attempt to introduce functional programming concepts into procedural languages. instead of for(int i =0 ; i < num; i++) doStuff(arr[i]);, you can instead assume that the elements of the array inherently can have "stuff done to them" so arr.each do |el| doStuff(el) end

You're only exemplifying an anonymous function, not the closure. Wikiedpia: The term closure is often mistakenly used to mean anonymous function. This is probably because most languages implementing anonymous functions allow them to form closures and programmers are usually introduced to both concepts at the same time. These are, however, distinct concepts. A closure retains a reference to the environment at the time it was created (for example, to the current value of a local variable in the enclosing scope) while a generic anonymous function need not do this.
–
JakobMar 21 '11 at 7:13