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

Converting Func<> types

Cannot convert type 'System.Func' to 'System.Func' Trying to cast f2 to f1: Func f1 = x => true; Func f2 = x => true; f1 = (Func)f2; Tried map function to solve but, this…
jack-london
  • 1,599
  • 3
  • 21
  • 42
12
votes
4 answers

Clojure: How to generate a 'trie'?

Given the following... (def inTree '((1 2) (1 2 3) (1 2 4 5 9) (1 2 4 10 15) (1 2 4 20 25))) How would you transform it to this trie? (def outTrie '(1 (2 () (3 ()) (4 (5 (9 ())) (10 …
Johnny
  • 1,144
  • 2
  • 11
  • 23
12
votes
1 answer

How to curry a function in Scala

I'm trying to call a 2 parameters function in List.foreach, with the first parameter fixed for a loop. In fact I want to curry a function of two parameters into a function of one parameter which returns a function of one parameter (as List.foldLeft…
Maxime
  • 2,048
  • 1
  • 27
  • 38
12
votes
5 answers

In pure functional languages, is data (strings, ints, floats.. ) also just functions?

I was thinking about pure Object Oriented Languages like Ruby, where everything, including numbers, int, floats, and strings are themselves objects. Is this the same thing with pure functional languages? For example, in Haskell, are Numbers and…
12
votes
1 answer

Scala: List of pairs to pair of lists

I have a list of pairs: val pairs = List("a" -> 1, "b" -> 2, "c" -> 3) I'd like to convert it to a pair of lists: List("a", "b", "c") -> List(1, 2, 3) Basically, I want the opposite of zip() Any elegant way of doing so?
Electric Monk
  • 2,192
  • 2
  • 23
  • 33
12
votes
3 answers

Should I represent database data with immutable or mutable data structures?

I'm currently programming in Scala, but I guess this applies to any functional programming language, or rather, any programming language that recommends immutability and can interact with a database. When I fetch data from my database, I map it to a…
12
votes
1 answer

How to combine Haskell code with Objective-C for iOS development?

I want to start iOS development and I' m very interested in the ways of using Haskell language as opposed to the Objective-C/C++ in the iOS environment. Let's suppose that we have some Haskell code which uses different Haskell libraries and we want…
Oleksandr Karaberov
  • 12,573
  • 10
  • 43
  • 70
12
votes
5 answers

When to expose constructors of a data type when designing data structures?

When designing data structures in functional languages there are 2 options: Expose their constructors and pattern match on them. Hide their constructors and use higher-level functions to examine the data structures. In what cases, what is…
Petr
  • 62,528
  • 13
  • 153
  • 317
12
votes
8 answers

Most elegant combinations of elements in F#

One more question about most elegant and simple implementation of element combinations in F#. It should return all combinations of input elements (either List or Sequence). First argument is number of elements in a combination. For example: comb 2…
The_Ghost
  • 2,070
  • 15
  • 26
12
votes
2 answers

Practical application of "Bananas, Lenses, Envelopes, and Barbed Wire"?

First of all, the goofy title is directly referencing this paper: http://eprints.eemcs.utwente.nl/7281/01/db-utwente-40501F46.pdf I understand the theoretical value of this, as it models most, if not all, programming semantics. What problems are…
Jeremy Powell
  • 3,426
  • 2
  • 21
  • 29
12
votes
3 answers

Composing a list of all pairs

I'm brand new to Scala, having had very limited experience with functional programming through Haskell. I'd like to try composing a list of all possible pairs constructed from a single input list. Example: val nums = List[Int](1, 2, 3, 4, 5) //…
KChaloux
  • 3,918
  • 6
  • 37
  • 52
12
votes
2 answers

Describe the Damas-Milner type inference in a way that a CS101 student can understand

Hindley-Milner is a type system that is the basis of the type systems of many well known functional programming languages. Damas-Milner is an algorithm that infers (deduces?) types in a Hindley-Milner type system. Wikipedia gives a description of…
user128807
  • 10,447
  • 17
  • 53
  • 72
12
votes
2 answers

What are some obvious optimizations for a virtual machine implementing a functional language?

I'm working on an intermediate language and a virtual machine to run a functional language with a couple of "problematic" properties: Lexical namespaces (closures) Dynamically growing call stack A slow integer type (bignums) The intermediate…
12
votes
3 answers

Is currying the same as overloading?

Is currying for functional programming the same as overloading for OO programming? If not, why? (with examples if possible) Tks
Marcelo de Aguiar
  • 1,432
  • 12
  • 31
12
votes
3 answers

what is a fully type-inferred language? and limitations of such language?

As far as I know,any programming language which doesn't require to write type annotations in the source while writing a function or module and if that chunk of code is "type-correct" , compiler will infer the types and compiles the code. is there…
1 2 3
99
100