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.
746 questions
187
votes
15
answers
90k
views
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). ...
137
votes
5
answers
38k
views
Am I too 'clever' to be readable by Jr. devs? Too much functional programming in my JS? [closed]
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 ...
118
votes
3
answers
116k
views
What is the name of a function that takes no argument and returns nothing? [closed]
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.
.....
112
votes
3
answers
16k
views
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 ...
103
votes
2
answers
26k
views
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 ...
98
votes
5
answers
32k
views
Functional Programming vs. OOP [closed]
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?
88
votes
6
answers
62k
views
Where are all the functional programming design patterns? [closed]
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 ...
81
votes
14
answers
37k
views
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 ...
79
votes
10
answers
17k
views
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 ...
75
votes
4
answers
16k
views
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 ...
74
votes
4
answers
14k
views
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 ...
72
votes
5
answers
11k
views
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 ...
71
votes
12
answers
9k
views
"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 ...
69
votes
4
answers
13k
views
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 ...
65
votes
12
answers
21k
views
Why isn't functional programming more popular in the industry? Does it catch on now? [closed]
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 ...
65
votes
4
answers
11k
views
what is the purpose of arrows?
I am learning functionnal programming with Haskell, and I try to grab concepts by first understanding why do I need them.
I would like to know the goal of arrows in functional programming languages. ...
64
votes
10
answers
31k
views
Why would a program use a closure?
After reading many posts explaining closures here I'm still missing a key concept: Why write a closure? What specific task would a programmer be performing that might be best served by a closure?
...
63
votes
4
answers
23k
views
What are combinators and how are they applied to programming projects? (practical explanation)
What are combinators?
I'm looking for:
a practical explanation
examples of how they are used
examples of how combinators improve the quality/generality of code
I'm not looking for:
explanations of ...
60
votes
6
answers
60k
views
What is the difference between a function and a lambda?
I'm a little bit confused about 'function' and 'lambda'. I've seen some examples showing that the scheme keyword lambda works very similarly to the JavaScript keyword function, but I really don't ...
59
votes
12
answers
12k
views
What programming language generates fewest hard-to-find bugs? [closed]
What language, in your opinion, allows the average programmer to output features with the least amount of hard-to-find bugs? This is of course, a very broad question, and I'm interested in very broad ...
58
votes
4
answers
13k
views
What is the origin and meaning of the phrase “Lambda the ultimate?”
I've been messing around with functional programming languages for a few years, and I keep encountering this phrase. For example, it is a chapter of "The Little Schemer, which certainly predates ...
57
votes
5
answers
10k
views
Is it still valid to speak about anemic model in the context of functional programming?
Most of DDD tactical design patterns belong to object-oriented paradigm, and anemic model describes the situation when all business logic is put into services rather than objects thus making them a ...
55
votes
11
answers
12k
views
"Easy to reason about" - what does that mean? [closed]
I have heard a lot of times when other developers use that phrase to "advertise" some patterns or developing best practices. Most of the time this phrase is used when you are talking about benefits of ...
54
votes
6
answers
40k
views
Choosing a functional programming language [closed]
I have read a lot of threads about functional programming languages lately (almost in the past year, in fact). I would really like to pick one and learn it thoroughly.
Last [course] semester, I have ...
54
votes
3
answers
27k
views
What is a lambda, and why would it be useful? [closed]
So far I heard about :
Lambda calculus
Lambda programming
Lambda expressions
Lambda functions
Which all seems to be related to functional programming...
Apparently it will be integrated into C++1x, ...
54
votes
3
answers
7k
views
Why is an anemic domain model considered bad in C#/OOP, but very important in F#/FP?
In a blog post on F# for fun and profit, it says:
In a functional design, it is very important to separate behavior from
data. The data types are simple and "dumb". And then separately, you
have ...
53
votes
2
answers
9k
views
What did Alan Kay mean by "assignment" in The Early History of Smalltalk?
I have been reading The Early History of Smalltalk and there are a few mentions of "assignment" which make me question my understanding of its meaning:
Though OOP came from many motivations, two ...
52
votes
1
answer
10k
views
How do you design programs in Haskell or other functional programming languages?
I have some experience in object oriented programming languages like c# or ruby. I know how to design a program in object oriented style, how to create classes and objects, and how to define relations ...
52
votes
7
answers
25k
views
Workaround for Java checked exceptions
I appreciate a lot the new Java 8 features about lambdas and default methods interfaces. Yet, I still get bored with checked exceptions. For instance, if I just want to list all the visible fields of ...
51
votes
14
answers
8k
views
Why the current enthusiasm for Functional Programming? [closed]
I've been hearing a lot of enthusiasm about functional programming languages lately, with regards to Scala, Clojure, and F#. I've recently started studying Haskell, to learn the FP paradigm.
I love ...
50
votes
9
answers
14k
views
Return considered harmful? Can code be functional without it?
OK, so the title is a little clickbaity but seriously I've been on a tell, don't ask (TDA) kick for a while. I like how it encourages methods to be used as messages in true object-oriented fashion. ...
50
votes
5
answers
19k
views
What is it about functional programming that makes it inherently adapted to parallel execution? [duplicate]
I've been reading over and over that functional languages are ideal (or at least very often useful) for parallelism. Why is this? What core concepts and paradigms are typically employed and which ...
48
votes
7
answers
25k
views
Haskell AND Lisp vs. Haskell OR Lisp [closed]
I currently code with C, C++, and Python. I'm wanting to pick up a functional programming language, and right now I'm leaning toward Haskell. I do NOT want to start a "Haskell vs Lisp" war here; what ...
48
votes
7
answers
28k
views
What do you call a function where the same input will always return the same output, but also has side effects?
Say we have a normal pure function such as
function add(a, b) {
return a + b
}
And then we alter it such that it has a side effect
function add(a, b) {
writeToDatabase(Math.random())
return a +...
47
votes
5
answers
7k
views
Critique of the IO monad being viewed as a state monad operating on the world
The IO monad in Haskell is often explained as a state monad where the state is the world. So a value of type IO a monad is viewed as something like worldState -> (a, worldState).
Some time ago I ...
46
votes
2
answers
18k
views
Equivalent of SOLID principles for functional programming
I've found the SOLID principles quite useful when thinking about object-oriented design.
Is there a similar / equivalent set of language-agnostic principles tailored for functional programming?
46
votes
5
answers
13k
views
How is dependency inversion related to higher-order functions?
Today I've just seen this article which described the relevance of SOLID principle in F# development-
F# and Design principles – SOLID
And while addressing the last one - "Dependency inversion ...
46
votes
6
answers
8k
views
Are closures considered impure functional style?
Are closures considered impure in functional programming?
It seems one can generally avoid closures by passing values directly to a function. Therefore should closures be avoided where possible?
If ...
44
votes
7
answers
10k
views
Functional Programming on the rise?
I have noticed lately that functional programming languages are gaining popularity. I recently saw how the Tiobe Index shows an increase in their popularity in comparison to the last year although ...
44
votes
8
answers
19k
views
Are functional languages better at recursion?
TL;DR : Do functional languages handle recursion better than non-functional ones?
I am currently reading Code Complete 2. At some point in the book, the author warns us about recursion. He says it ...
44
votes
2
answers
11k
views
Why are lists the data structure of choice in functional languages?
Most functional languages use linked lists as their primary immutable data structure. Why lists, and not e.g. trees? Trees can also reuse paths, and even model lists.
44
votes
2
answers
6k
views
Why (or why not) are existential types considered bad practice in functional programming?
What are some techniques I might use to consistently refactor code removing the reliance on existential types? Typically these are used to disqualify undesired constructions of your type as well as to ...
43
votes
7
answers
12k
views
Are small amounts of functional programming understandable by non-FP people? [closed]
Case: I'm working at a company, writing an application in Python that is handling a lot of data in arrays. I'm the only developer of this program at the moment, but it will probably be used/modified/...
43
votes
8
answers
19k
views
Is Functional Programming possible in Java? [closed]
I was browsing through the Amazon.com Bookstore and I came across the book "Functional Programming for Java Developers".
I know some very basic Functional Programming and have been programming in ...
43
votes
1
answer
14k
views
How to organize functional programs [closed]
Possible Duplicate:
Functional Programming vs. OOP
How to write manageable code with functional programming?
In OOP, your basic unit of organization for code is the class. A frequently used ...
42
votes
2
answers
8k
views
Misconceptions about purely functional languages?
I often encounter the following statements / arguments:
Pure functional programming languages do not allow side effects (and are therefore of little use in practice because any useful program does ...
41
votes
7
answers
16k
views
Maybe monad vs exceptions
I wonder what are the advantages of Maybe monad over exceptions? It looks like Maybe is just explicit (and rather space-consuming) way of try..catch syntax.
update Please note that I'm intentionally ...
41
votes
6
answers
5k
views
Why Functional Programming
What is the deal with functional programming? I see talk about it a lot but to be honest I've never found them at all useful. Why do so many universities apparently teach them?
40
votes
4
answers
14k
views
What is referential transparency?
I have seen that in imperative paradigms
f(x)+f(x)
might not be the same as:
2*f(x)
But in a functional paradigm it should be the same. I have tried to implement both cases in Python and Scheme, ...
40
votes
5
answers
14k
views
Does immutability entirely eliminate the need for locks in multi-processor programming?
Part 1
Clearly Immutability minimizes the need for locks in multi-processor programming, but does it eliminate that need, or are there instances where immutability alone is not enough? It seems to me ...