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
3 answers

Aggregate list values in Scala

Starting with a list of objects containing two parameters notional and currency, how can I aggregate the total notional per currency? Given: case class Trade(name: String, amount: Int, currency: String) val trades = List( Trade("T150310",…
parkr
  • 3,188
  • 5
  • 35
  • 39
11
votes
4 answers

What's the "functional way" to avoid passing state-choosing context down the call stack?

Say I have a trait that has two lists. Sometimes I'm interested in the one, sometimes in t'other. trait ListHolder { val listOne = List("foo", "bar") val listTwo = List("bat", "baz") } I have a chain of function calls, at the top of which I…
Larry OBrien
  • 8,484
  • 1
  • 41
  • 75
11
votes
2 answers

Can I build a graphical interface from ocaml toplevel?

À few questions regarding the interactive toplevel and graphical UI programming: Is it possible to build a graphical interface dynamically from ocaml toplevel? It is possible to use the Graphics library too?
11
votes
4 answers

How to functionally merge overlapping number-ranges from a List

I have a number of range-objects which I need to merge so that all overlapping ranges disappear: case class Range(from:Int, to:Int) val rangelist = List(Range(3, 40), Range(1, 45), Range(2, 50), etc) Here is the ranges: 3 40 1 45 2 50…
recalcitrant
  • 939
  • 11
  • 23
11
votes
3 answers

Kadane's Algorithm in Scala

Does anyone have a Scala implementation of Kadane's algorithm done in a functional style? Edit Note: The definition on the link has changed in a way that invalidated answers to this question -- which goes to show why questions (and answers) should…
S0rin
  • 1,283
  • 1
  • 10
  • 22
11
votes
1 answer

laziness and function composition (haskell, erlang)

Can someone please explain or give some resources on how function composition works in relation to laziness? For example how does filter (/='W') . map toUpper $ "justaword" work in Haskell compared to it's counterpart in erlang which is not lazy?
Adi
  • 562
  • 7
  • 18
11
votes
2 answers

Are there already built in functional C#/.NET constructs like these? g(h()), or

public static Func To(this Func g, Func h) { return () => h(g()); } public static Func ToIdentity(this T t) { return () => t; } I sometimes use these and others when delaying evaluation. Are these already in the…
lucidquiet
  • 6,124
  • 7
  • 51
  • 88
11
votes
1 answer

Monads in JavaScript?

How would an example JavaScript code look like that uses Monad? I'm asking because understanding Monad is much clearer if I can see a code example (and JavaScript being a simple, functional language it could be the best language to use to learn it).
Tower
  • 98,741
  • 129
  • 357
  • 507
11
votes
2 answers

What's the relation of fold on Option, Either etc and fold on Traversable?

Scalaz provides a method named fold for various ADTs such as Boolean, Option[_], Validation[_, _], Either[_, _] etc. This method basically takes functions corresponding to all possible cases for that given ADT. In other words, a pattern match shown…
missingfaktor
  • 90,905
  • 62
  • 285
  • 365
11
votes
2 answers

Haskell Print Lines in function

I am new to Haskell and I'm wondering if there's a way to output 'debug' lines within a function in Haskell? I.E. I want to debug what values are being inputted into a function My current code is import Prelude foo(a,b,c) print("input a : " ++…
AlanFoster
  • 8,156
  • 5
  • 35
  • 52
11
votes
3 answers

C# operators as functions

Is there a way to use operators as functions without declaring them manually? Func not = x => !x; Similar to (+)/(-) in Haskell. Would be handy in various LINQ scenarios involving conditional query construction. Maybe some C# (4.0+)…
UserControl
  • 14,766
  • 20
  • 100
  • 187
11
votes
5 answers

Homoiconic type theory

Lisp has the property of being homoiconic, that is, the representation of code used by the language implementation (lists) is also available to, and idiomatically used by, programs that want to represent code for their own purposes. The other major…
rwallace
  • 31,405
  • 40
  • 123
  • 242
11
votes
3 answers

What is the practical use for laziness as a built-in language feature?

It's fairly obvious why a functional programming language that wants to be lazy needs to be pure. I'm looking at the reverse question: if a language wants to be pure, is there a big advantage in being lazy? One argument, made by one of the designers…
11
votes
7 answers

Appending an element to a collection using LINQ

I am trying to process some list with a functional approach in C#. The idea is that I have a collection of Tuple and I want to change the Item 2 of some element T. The functional way to do so, as data is immutable, is to take the list,…
SRKX
  • 1,806
  • 1
  • 21
  • 42
11
votes
12 answers

Haskell Cons Operator (:)

I am really new to Haskell (Actually I saw "Real World Haskell" from O'Reilly and thought "hmm, I think I'll learn functional programming" yesterday) and I am wondering: I can use the construct operator to add an item to the beginning of a list: 1 :…
Carson Myers
  • 37,678
  • 39
  • 126
  • 176
1 2 3
99
100