Questions tagged [functional-programming]

Functional programming is a programming paradigm based upon building abstractions using functions, avoiding side effects and change of state. Pure functional programming is thread-safe.

Functional programming is a programming paradigm that deals primarily with mathematical functions. In functional languages, functions are first-class values.

Functions take arguments and return results, but typically don't mutate state. This in contrast to , which primarily revolves around statements that change state. The advantage of avoiding mutable state is that you can safely compose functions, and you can use algebraic laws and "substitution of equals for equals" to simplify programs or improve their performance.

One consequence of this is that many common patterns in programming can be abstracted as higher-order functions, which use a user-supplied function that implements real functionality, and apply it to data in a certain way. This can make code more concise and simpler to reason about and understand.

Functional programming has grown out of a mathematical system called lambda calculus, which was developed in the 1930s. was the first programming language to be based on the lambda calculus.

Today, functional programming is getting more and more popular. The main reason for this is the provability of functional programs' properties, and security is very important nowadays. There are many use cases for functional programming, e.g. Computations or Concurrency handling. Use cases of functional programming.

Programming languages

These languages are listed in order of popularity in relation to the functional-programming tag.

Languages that are primarily functional, although some also support mutable state or other programming paradigms:

Languages that have some functional aspects (like support for first class functions) but are not considered functional languages per se:

History and concepts

The Conception, Evolution, and Application of Functional Programming Languages by Paul Hudak.

17076 questions
1826
votes
29 answers

What is tail recursion?

Whilst starting to learn lisp, I've come across the term tail-recursive. What does it mean exactly?
1518
votes
46 answers

What is a monad?

Having briefly looked at Haskell recently, what would be a brief, succinct, practical explanation as to what a monad essentially is? I have found most explanations I've come across to be fairly inaccessible and lacking in practical detail.
ljs
  • 34,721
  • 32
  • 101
  • 123
1317
votes
40 answers

map function for objects (instead of arrays)

I have an object: myObject = { 'a': 1, 'b': 2, 'c': 3 } I am looking for a native method, similar to Array.prototype.map that would be used as follows: newObject = myObject.map(function (value, label) { return value * value; }); // newObject…
Randomblue
  • 98,379
  • 133
  • 328
  • 526
1150
votes
67 answers

Does JavaScript have a method like "range()" to generate a range within the supplied bounds?

In PHP, you can do... range(1, 3); // Array(1, 2, 3) range("A", "C"); // Array("A", "B", "C") That is, there is a function that lets you get a range of numbers or characters by passing the upper and lower bounds. Is there anything built-in to…
alex
  • 438,662
  • 188
  • 837
  • 957
1147
votes
18 answers

What is (functional) reactive programming?

I've read the Wikipedia article on reactive programming. I've also read the small article on functional reactive programming. The descriptions are quite abstract. What does functional reactive programming (FRP) mean in practice? What does reactive…
JtR
  • 20,259
  • 16
  • 44
  • 59
1080
votes
28 answers

Does functional programming replace GoF design patterns?

Since I started learning F# and OCaml last year, I've read a huge number of articles which insist that design patterns (especially in Java) are workarounds for the missing features in imperative languages. One article I found makes a fairly strong…
Juliet
  • 76,873
  • 44
  • 191
  • 224
940
votes
15 answers

List comprehension vs. lambda + filter

I happened to find myself having a basic filtering need: I have a list and I have to filter it by an attribute of the items. My code looked like this: my_list = [x for x in my_list if x.attribute == value] But then I thought, wouldn't it be better…
Agos
  • 16,699
  • 9
  • 52
  • 68
881
votes
6 answers

What part of Hindley-Milner do you not understand?

I swear there used to be a T-shirt for sale featuring the immortal words: What part of do you not understand? In my case, the answer would be... all of it! In particular, I often see notation like this in Haskell papers, but I have no clue what…
866
votes
13 answers

What is the difference between a 'closure' and a 'lambda'?

Could someone explain? I understand the basic concepts behind them but I often see them used interchangeably and I get confused. And now that we're here, how do they differ from a regular function?
sker
  • 15,764
  • 8
  • 35
  • 41
815
votes
4 answers

Functional programming vs Object Oriented programming

I've been mainly exposed to OO programming so far and am looking forward to learning a functional language. My questions are: When do you choose functional programming over object-oriented? What are the typical problem definitions where…
Olivier Lalonde
  • 17,330
  • 28
  • 69
  • 86
794
votes
19 answers

Monad in plain English? (For the OOP programmer with no FP background)

In terms that an OOP programmer would understand (without any functional programming background), what is a monad? What problem does it solve and what are the most common places it's used? Update To clarify the kind of understanding I was looking…
user65663
755
votes
15 answers

Getting started with Haskell

For a few days I've tried to wrap my head around the functional programming paradigm in Haskell. I've done this by reading tutorials and watching screencasts, but nothing really seems to stick. Now, in learning various imperative/OO languages (like…
user50685
693
votes
21 answers

What is 'Currying'?

I've seen references to curried functions in several articles and blogs but I can't find a good explanation (or at least one that makes sense!)
Ben
  • 9,591
  • 9
  • 32
  • 40
662
votes
15 answers

How can a time function exist in functional programming?

I've to admit that I don't know much about functional programming. I read about it from here and there, and so came to know that in functional programming, a function returns the same output, for same input, no matter how many times the function is…
Nawaz
  • 327,095
  • 105
  • 629
  • 812
563
votes
8 answers

Large-scale design in Haskell?

What is a good way to design/structure large functional programs, especially in Haskell? I've been through a bunch of the tutorials (Write Yourself a Scheme being my favorite, with Real World Haskell a close second) - but most of the programs are…
Dan
  • 5,773
  • 3
  • 15
  • 13
1
2 3
99 100