Questions tagged [functional-programming]

Functional programming is a paradigm which attempts to solve computational problems by the chained evaluation of functions whose output is determined by their inputs rather than the programme state. In this style of programming, side effects and mutable data are deprecated and usually strictly isolated.

Functional programming is a paradigm which attempts to solve computational problems by the chained evaluation of functions whose output is determined by their inputs rather than the programme state. In this style of programming, side effects and mutable data are deprecated and usually strictly isolated.

The disciplines of functional programming can be applied in almost any language, but in many imperative languages the resulting code is inelegant and verbose. A growing set of programming languages have been developed explicitly to enable expressive functional coding, including

  • Lisp, with its many dialects (e.g. Common Lisp, Scheme, Clojure)
  • ML/SML/OCaml
  • Haskell
  • Scala
  • Erlang
735 questions
182
votes
15 answers

What is the advantage of currying?

I just learned about currying, and while I think I understand the concept, I'm not seeing any big advantage in using it. As a trivial example I use a function that adds two values (written in ML). The version without currying would be fun add(x, y)…
Mad Scientist
  • 2,766
  • 2
  • 18
  • 19
135
votes
5 answers

Am I too 'clever' to be readable by Jr. devs? Too much functional programming in my JS?

I'm a Sr. front-end dev, coding in Babel ES6. Part of our app makes an API call, and based on the data model we get back from the API call, certain forms need to be filled out. Those forms are stored in a doubly-linked list (if the back-end says…
111
votes
3 answers

What is the name of a function that takes no argument and returns nothing?

In Java 8's java.util.function package, we have: Function: Takes one argument, produces one result. Consumer: Takes one argument, produces nothing. Supplier: Takes no argument, produces one result. ...: Other cases handling primitives, 2 arguments,…
superbob
  • 1,282
  • 2
  • 8
  • 11
110
votes
3 answers

Why do Trampolines work?

I've been doing some functional JavaScript. I had thought that Tail-Call Optimization had been implemented, but as it turns out I was wrong. Thus, I've had to teach myself Trampolining. After a bit of reading here and elsewhere, I was able to get…
Ucenna
  • 1,292
  • 2
  • 10
  • 19
102
votes
2 answers

What is the "Free Monad + Interpreter" pattern?

I've seen people talking about Free Monad with Interpreter, particularly in the context of data-access. What is this pattern? When might I want to use it? How does it work, and how would I implement it? I understand (from posts such as this) that…
Benjamin Hodgson
  • 4,488
  • 2
  • 25
  • 34
99
votes
5 answers

Functional Programming vs. OOP

I've heard a lot of talk about using functional languages such as Haskell as of late. What are some of the big differences, pros and cons of functional programming vs. object-oriented programming?
GSto
  • 8,531
  • 7
  • 39
  • 59
86
votes
6 answers

Where are all the functional programming design patterns?

OO programming literature is full of design patterns. Most books on object oriented programming dedicate a chapter or two to design patterns like factories and decorators. So what are the equivalent patterns in functional languages and why hasn't…
user7146
80
votes
14 answers

Why are side-effects considered evil in functional programming?

I feel that side effects are a natural phenomenon. But it is something like taboo in functional languages. What are the reasons? My question is specific to functional programming style. Not all programming languages/paradigms.
Gulshan
  • 9,402
  • 10
  • 58
  • 89
79
votes
10 answers

How functional programming achieves "No runtime exceptions"

How does a functional programming language, such as Elm, achieve "No runtime exceptions"? Coming from an OOP background, runtime exceptions have been part of whatever framework that is based on OOP, both browser-based frameworks based on JavaScript…
74
votes
4 answers

What are the biggest differences between F# and Scala?

F# and Scala are both functional programming langugages that don't force the developer to only use immutable datatypes. They both have support for objects, can use libraries written in other languages and run on a virtual machine. Both languages…
Jonas
  • 14,867
  • 9
  • 69
  • 102
73
votes
4 answers

How do functional languages handle random numbers?

What I mean about that is that in nearly every tutorial I've read about functional languages, is that one of the great things about functions, is that if you call a function with the same parameters twice, you'll always end up with the same…
Electric Coffee
  • 1,465
  • 1
  • 14
  • 22
71
votes
5 answers

In functional programming, does having most of the data structures immutable require more memory usage?

In functional programming since almost all data structure are immutable, when the state has to change a new structure is created. Does this mean a lot more memory usage? I know the object oriented programming paradigm well, now I'm trying to learn…
Jbemmz
  • 812
  • 1
  • 6
  • 9
70
votes
12 answers

"Everything is a Map", am I doing this right?

I watched Stuart Sierra's talk "Thinking In Data" and took one of the ideas from it as a design principle in this game I'm making. The difference is he's working in Clojure and I'm working in JavaScript. I see some major differences between our…
69
votes
4 answers

Is functional programming faster in multithreading because I write things differently or because things are compiled differently?

I'm diving into the world of functional programming and I keep reading everywhere that functional languages are better for multithreading/multicore programs. I understand how functional languages do a lot of things differently, such as recursion,…
Aventinus
  • 801
  • 1
  • 7
  • 10
65
votes
12 answers

Why isn't functional programming more popular in the industry? Does it catch on now?

During my four years at university we have been using much functional programming in several functional programming languages. But I have also used much object oriented programming to, and in fact I use object oriented languages more when doing my…
Jonas
  • 14,867
  • 9
  • 69
  • 102
1
2 3
48 49