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.

18902 questions
2033
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?
1768
votes
41 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
  • 112,777
  • 145
  • 353
  • 547
1677
votes
47 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
  • 37,275
  • 36
  • 106
  • 124
1626
votes
90 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
  • 479,566
  • 201
  • 878
  • 984
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,568
  • 17
  • 46
  • 60
1144
votes
29 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
  • 80,494
  • 45
  • 196
  • 228
1089
votes
17 answers

List comprehension vs. lambda + filter

I have a list that I want to filter by an attribute of the items. Which of the following is preferred (readability, performance, other reasons)? xs = [x for x in xs if x.attribute == value] xs = filter(lambda x: x.attribute == value, xs)
Agos
  • 18,542
  • 11
  • 56
  • 70
975
votes
16 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
  • 17,842
  • 8
  • 37
  • 41
925
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…
882
votes
21 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
851
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
  • 19,423
  • 28
  • 76
  • 91
803
votes
24 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
  • 10,931
  • 9
  • 38
  • 47
754
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
673
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
  • 353,942
  • 115
  • 666
  • 851
562
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,763
  • 3
  • 17
  • 13
1
2 3
99 100