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
12
votes
6 answers

Functional programming: immutability etc

I recently asked a question about functional programming, and received (good!) answers that prompted more questions (as seems to be the case with learning, sometimes). Here are a couple examples: One answer made reference to an advantage of…
J Cooper
  • 16,891
  • 12
  • 65
  • 110
12
votes
3 answers

In functional programming, can a function call another function that was declared outside of it's scope and not passed as a parameter?

Does using a function declared outside the scope of the function it is being used in violate a Functional principle like immutability? Or is that referring specifically to data like arrays, strings, etc. For example: var data ["cat", "dog",…
Michael
  • 501
  • 5
  • 12
12
votes
2 answers

Choosing between overloaded methods if actual parameter is a lambda

In Java 1.8, the following lambda expression complies with both Runnable and Callable functional interfaces: () -> { throw new RuntimeException("FIXME"); } Still, if I submit it to an ExecutorService using a single-argument method, and ignore…
Bass
  • 4,977
  • 2
  • 36
  • 82
12
votes
2 answers

What are the state-of-art methods for solving functional equations?

Suppose that you want to find a λ-calculus program, T, that satisfies the following equations: (T (λ f x . x)) = (λ a t . a) (T (λ f x . (f x))) = (λ a t . (t a)) (T (λ f x . (f (f x)))) = (λ a b t . (t a b)) (T (λ f x . (f (f…
MaiaVictor
  • 51,090
  • 44
  • 144
  • 286
12
votes
3 answers

Is there any intuition to understand join two functions in Monad?

join is defined along with bind to flatten the combined data structure into single structure. From type system view, (+) 7 :: Num a => a -> a could be considered as a Functor, (+) :: Num a => a -> a -> a could be considered as a Functor of Functor,…
Kamel
  • 1,856
  • 1
  • 15
  • 25
12
votes
4 answers

Proper commenting for functional programming

I've been learning scheme, and I just realized that I don't really know how to properly comment my functional scheme code. I know how to add a comment of course - you add a ; and put your comment after it. My question is what should I put in my…
Cam
  • 14,930
  • 16
  • 77
  • 128
12
votes
4 answers

What to call OOP's equivalent of "referential transparency"?

My understanding is that the term "referential transparency" can really only be applied to functional code. However, a method call on an object in object-oriented code can have a similar property, which is that the return value of the method, and…
mjs
  • 63,493
  • 27
  • 91
  • 122
12
votes
5 answers

Why should I avoid using local modifiable variables in Scala?

I'm pretty new to Scala and most of the time before I've used Java. Right now I have warnings all over my code saying that i should "Avoid mutable local variables" and I have a simple question - why? Suppose I have small problem - determine max int…
Oleksii Duzhyi
  • 1,203
  • 3
  • 12
  • 26
12
votes
7 answers

What's a good way to rewrite this non-tail-recursive function?

For some reason, I am having trouble thinking of a good way to rewrite this function so it uses constant stack space. Most online discussions of tree recursion cheat by using the Fibonacci function and exploiting the properties of that particular…
12
votes
1 answer

Convert Swift Array to Dictionary with indexes

I'm using Xcode 6.4 I have an array of UIViews and I want to convert to a Dictionary with keys "v0", "v1".... Like so: var dict = [String:UIView]() for (index, view) in enumerate(views) { dict["v\(index)"] = view } dict //=> ["v0": , "v1":…
Adam
  • 783
  • 1
  • 7
  • 11
12
votes
6 answers

For real time programming, does reference counting have an advantage over garbage collection in terms of determinism?

If you were designing a programming language that features automatic memory management, would using reference counting allow for determinism guarantees that are not possible with a garbage collector? Would there be a different answer to this…
12
votes
3 answers

Efficient persistent data structures for relational database

I'm looking for material on persistent data structures that can be used to implement a relational model. Persistence in the meaning of immutable data structures. Anyone know of some good resources, books, papers and such? (I already have the book…
12
votes
2 answers

Datatype-generic programming libraries for Scala

I'm looking for a Scala library allowing for datatype-generic programming (like Scrap Your Boilerplate, for example). A list of libraries with appropriate links and short descriptions for each one would be a perfect answer.
Marat Salikhov
  • 6,367
  • 4
  • 32
  • 35
12
votes
4 answers

java: libraries for immutable functional-style data structures

This is very similar to another question (Functional Data Structures in Java) but the answers there are not particularly useful. I need to use immutable versions of the standard Java collections (e.g. HashMap / TreeMap / ArrayList / LinkedList /…
Jason S
  • 184,598
  • 164
  • 608
  • 970
12
votes
2 answers

Coq: Prop versus Set in Type(n)

I want to consider the following three (related?) Coq definitions. Inductive nat1: Prop := | z1 : nat1 | s1 : nat1 -> nat1. Inductive nat2 : Set := | z2 : nat2 | s2 : nat2 -> nat2. Inductive nat3 : Type := | z3 : nat3 | s3 : nat3 ->…
Jonathan Gallagher
  • 2,115
  • 2
  • 17
  • 31