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
1 answer

Am I using randomRIO wrong?

I'm trying to show on Terminal a random number between 1 and 7... nRandom :: IO () nRandom = do number <- randomRIO (1,7) putStrLn ("Your random number is: "++show number) ...but ghc doesn't compile it and I get errors like: No instance…
GniruT
  • 731
  • 1
  • 6
  • 14
12
votes
3 answers

How do I represent variants (sum-types) in JSON?

Algebraic data types are a way to accurately describe the data. When it comes to JSON there is no problem with product types, that is each structure is listing props one-by-one that belong to them. However it's not clear what to do with a sum-types…
Trident D'Gao
  • 18,973
  • 19
  • 95
  • 159
12
votes
1 answer

Scala Catalog of functional Design Patterns

Since a week I'm reading Programming in Scala. The authors introduce elements of the language step by step , but I'm still confused when to use the functional things like actors, closures, currying,.... I'm looking for a catalog of typical use…
stacker
  • 68,052
  • 28
  • 140
  • 210
12
votes
6 answers

An alternative to an array of functions?

I'm programming an app (php) which requires a very long list of similar yet different functions, which are being called by a set of keys: $functions = [ "do this" => function() { // does this }, "do that" => function() { …
Roy
  • 1,307
  • 1
  • 13
  • 29
12
votes
6 answers

Scala: how to understand the flatMap method of Try?

The flatMap method of the Success is implemented like this: def flatMap[U](f: T => Try[U]): Try[U] = try f(value) catch { case NonFatal(e) => Failure(e) } I kinda understand what this method is doing, it helps us to avoid…
12
votes
1 answer

How do I parse a string to a list of floats using functional style?

I am trying to parse a string into a list of floating-point values in Rust. I would assume there is a clever way to do this using iterators and Options; however, I cannot get it to ignore the Err values that result from failed parse() calls. The…
Jeff
  • 123
  • 1
  • 6
12
votes
3 answers

Is it ever possible to detect sharing in Haskell?

In Scheme, the primitive eq? tests whether its arguments are the same object. For example, in the following list (define lst (let (x (list 'a 'b)) (cons x x))) The result of (eq? (car x) (cdr x)) is true, and moreover it is true without…
Chris Taylor
  • 46,912
  • 15
  • 110
  • 154
12
votes
3 answers

Python: Map calling a function not working

Map not calling the function being passed. class a: def getDateTimeStat(self,datetimeObj): print("Hello") if __name__ == "__main__": obj = a() print("prog started") data = [1,2,3,4,5] b =…
Ankit Solanki
  • 670
  • 2
  • 9
  • 23
12
votes
4 answers

Coding Practice for F#

I have been dabbling with F# in Visual Studio 2010. I am a developer with more code/architecture design experience in object-oriented languages such as C# and Java. To expand my skill set and help make better decisions I am trying different…
Russell
  • 17,481
  • 23
  • 81
  • 125
12
votes
6 answers

Erlang : Returning from a function

I have a function in which I have a series of individual case statements. case ... of ... end, case ... of ... end, ... etc. I want to return from the function immediately when a particular case condition occurs in one of the case…
jeffreyveon
  • 13,400
  • 18
  • 79
  • 129
12
votes
5 answers

Is recursion in scala very necessary?

In the coursera scala tutorial, most examples are using top-down iterations. Partially, as I can see, iterations are used to avoid for/while loops. I'm from C++ and feel a little confused about this. Is iteration chosen over for/while loops? Is it…
galaapples
  • 205
  • 2
  • 8
12
votes
1 answer

When to use interfaces, and when to use higher order functions?

Given a ASP.NET MVC application with the following layers: UI (Views, CSS, Javascript, etc.) Controllers Services (Contains business logic, and data access) The reason for no separate data access layer, is that I'm using SQL type provider. (The…
ebb
  • 9,297
  • 18
  • 72
  • 123
12
votes
5 answers

How do Erlang actors differ from OOP objects?

Suppose I have an Erlang actor defined like this: counter(Num) -> receive {From, increment} -> From ! {self(), new_value, Num + 1} counter(Num + 1); end. And similarly, I have a Ruby class defined like this: class Counter …
rlkw1024
  • 6,455
  • 1
  • 36
  • 65
12
votes
1 answer

Understanding foldl in ML

I need to write a function that takes a list of strings and finds the largest string in the list. The catch is it needs to iterate through the list using List.foldl and cannot use recursive calls except for those in the library function of…
12
votes
0 answers

What's the difference between content in book (1999) and thesis (1996) for Chris Okasaki — Purely Functional Data Structures

I want to read Purely Functional Data Structure work. I've easily found thesis (which is freely available, 1996), but see that there's a book available also (1999). So I'd like to know how big is the difference (except two last chapters). I also…
Konstantine Rybnikov
  • 2,457
  • 1
  • 22
  • 29