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.

Filter by
Sorted by
Tagged with
99 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?
GSto's user avatar
  • 8,531
47 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?
mikera's user avatar
  • 20.7k
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/...
kd35a's user avatar
  • 533
40 votes
7 answers
15k 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 ...
Vladimir's user avatar
  • 503
32 votes
1 answer
1k views

Performance of single-assignment ADT oriented code on modern CPUs

Working in immutable data with single assignments has the obvious effect of requiring more memory, one would presume, because you're constantly creating new values (though compilers under the covers ...
Jimmy Hoffa's user avatar
  • 16.1k
6 votes
1 answer
3k views

Which problems domains are more suited to functional programming solutions [closed]

Which problems domains are more suited to functional programming solutions and why? Can anyone provide any examples? EDIT Just to clarify, I'm not asking for a list of problems. I want to know what ...
Tom Squires's user avatar
  • 17.7k
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 ...
Joanis's user avatar
  • 1,364
49 votes
9 answers
13k 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. ...
candied_orange's user avatar
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 ...
Vinoth Kumar C M's user avatar
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 ...
GlenPeterson's user avatar
  • 14.9k
27 votes
5 answers
8k views

Functional Programming: right ideas about concurrency and state?

FP proponents have claimed that concurrency is easy because their paradigm avoids mutable state. I don't get it. Imagine we're creating a multiplayer dungeon crawl (a roguelike) using FP where we ...
Mario T. Lanza's user avatar
24 votes
5 answers
9k views

For what common problems is functional programming not a good fit? [closed]

Functional programming is a declarative paradigm. One of the strenghts with FP is that side-effects are avoided. It's said that for some problems FP isn't a good fit. For what common problems isn't ...
Jonas's user avatar
  • 14.9k
19 votes
5 answers
3k views

What makes JVM so much versatile to support so many JVM languages?

JVM supports so many languages other than Java like Groovy,Clojure,Scala etc which are functional languages unlike Java(I am referring to Java before Version 8 where Lambda's are not supported) that ...
Geek's user avatar
  • 5,167
184 votes
15 answers
89k 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). ...
Mad Scientist's user avatar
65 votes
12 answers
20k 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 ...
Jonas's user avatar
  • 14.9k
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 ...
user2179977's user avatar
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 ...
Gulshan's user avatar
  • 9,442
43 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 ...
edalorzo's user avatar
  • 2,656
40 votes
4 answers
13k 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, ...
asgard's user avatar
  • 667
13 votes
1 answer
16k views

Why is imperative programming preferred over functional programming? [closed]

Background: I am proponent of functional programming who works at a VB.NET shop where the prevailing mental model is imperative programming. Being that foundation of our system is WinForms I can ...
Mario T. Lanza's user avatar
13 votes
9 answers
5k views

Resources for improving your comprehension of recursion? [closed]

I know what recursion is (when a patten reoccurs within itself, typically a function that calls itself on one of its lines, after a breakout conditional... right?), and I can understand recursive ...
Andrew M's user avatar
  • 1,101
12 votes
2 answers
3k views

Can we really use immutability in OOP without losing all key OOP features?

I see the benefits of making objects in my program immutable. When I am really deeply thinking about a good design for my application I often naturally arrive at many of my objects being immutable. It ...
lishaak's user avatar
  • 467
11 votes
5 answers
1k views

In functional programming how does one achieve modularity through mathematical laws?

I read in this question that functional programmers tend to use mathematical proofs to ensure that their program is working correctly. This sounds alot easier and faster than unit testing, but coming ...
leeand00's user avatar
  • 472
115 votes
3 answers
109k 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. .....
superbob's user avatar
  • 1,322
103 votes
2 answers
25k 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 ...
Benjamin Hodgson's user avatar
73 votes
4 answers
13k 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 ...
Electric Coffee's user avatar
70 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 ...
Daniel Kaplan's user avatar
63 votes
10 answers
30k 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? ...
Bendrix's user avatar
  • 759
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 ...
Danny Tuppeny's user avatar
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 ...
Olivier Dagenais's user avatar
50 votes
5 answers
18k 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 ...
Louis Thibault's user avatar
47 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 ...
Zeke's user avatar
  • 1,844
42 votes
6 answers
4k 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?
user avatar
31 votes
6 answers
7k views

Does learning a functional language make a better OOP programmer? [closed]

As a Java/C#/C++ programmer I hear a lot of talk about functional languages, but have never found a need to learn one. I've also heard that the higher level of thinking introduced in functional ...
GavinH's user avatar
  • 666
31 votes
8 answers
13k views

Why is the concept of lazy evaluation useful?

It seems lazy evaluation of expressions can cause a programmer to lose control over the order in which their code is executed. I am having trouble understanding why this would be acceptable or desired ...
user avatar
27 votes
6 answers
7k views

Is functional programming a superset of object oriented?

The more functional programming I do, the more I feel like it adds an extra layer of abstraction that seems like how an onion's layer is- all encompassing of the previous layers. I don't know if this ...
Jimmy Hoffa's user avatar
  • 16.1k
25 votes
3 answers
8k views

Is there a canonical tutorial or book on functional programming concepts? [closed]

Coming from a procedural/OO programming background, I tend to write Scheme programs in a procedural fashion. I would be intersted in learning Scheme or Lisp in a functional way from the ground up, to ...
Federico klez Culloca's user avatar
25 votes
5 answers
10k views

Is objected oriented programming paradigm outdated since it is anti-modular and anti-parallel? [closed]

I have read the controversial article Teaching FP to freshmen posted by Robert Harper who is a professor in CMU. He claimed that CMU would no longer teach object oriented programming in the ...
xiao's user avatar
  • 995
21 votes
7 answers
9k views

Can functional programming be used to develop a full enterprise application?

I am just beginning to learn Functional programming (FP). I come from a OOP world, where everything are objects, and most of them are mutable. I have a hard time wrapping around the concept that ...
user2434's user avatar
  • 1,277
19 votes
3 answers
1k views

Are there any empirical studies on the effect of different languages on software quality?

The proponents of functional programming languages assert that functional programming makes it easier to reason about code. Those in favor of statically typed languages say that their compilers catch ...
jgre's user avatar
  • 291
19 votes
5 answers
5k views

Why is reading from memory not a side-effect but reading from a file is?

What does exactly make reading from the process memory a pure operation? Suppose I created an array of 100 integers in the global memory and then took the 42th element of this array. It is not a side ...
ZhekaKozlov's user avatar
17 votes
5 answers
2k views

Is the semantic contract of an interface (OOP) more informative than a function signature (FP)?

It is said by some that if you take SOLID principles to their extremes, you end up at functional programming. I agree with this article but I think that some semantics are lost in the transition from ...
Alex's user avatar
  • 1,233
16 votes
8 answers
4k views

Mental Models or Real-World-Metaphors for Functional Programming

Does anyone have a good mental model or metaphor for functional programming which references something in the real world? Object Oriented programing intuitively makes sense to me. There are things ...
Guido Anselmi's user avatar
15 votes
4 answers
3k views

Does groovy call partial application 'currying'?

Groovy has a concept that it calls 'currying'. Here's an example from their wiki: def divide = { a, b -> a / b } def halver = divide.rcurry(2) assert halver(8) == 4 My understanding of what's ...
Richard Warburton's user avatar
14 votes
4 answers
1k views

Isn't functional paradigm too divergent with underlying hardware to be generally efficient?

Inspired by a question from SO: https://stackoverflow.com/questions/6623391/how-to-gain-control-of-a-5gb-heap-in-haskell It can be a long debate about FP's numerous advantages and disadvantages, but ...
vines's user avatar
  • 1,186
12 votes
2 answers
1k views

Haskell ways to the 3n+1 problem

Here is a simple programming problem from SPOJ: http://www.spoj.com/problems/PROBTRES/. Basically, you are asked to output the biggest Collatz cycle for numbers between i and j. (Collatz cycle of a ...
haskell looks great's user avatar
11 votes
1 answer
8k views

In the context of functional programming, what are 'total' functions and 'partial' functions?

I'm not finding via Google any explanation that my brain can grasp. Can someone explain this, and if possible, give an example of each using either pseudocode or C#? The term 'total' function was ...
Rock Anthony Johnson's user avatar
10 votes
4 answers
3k views

Why not apply Interface Segregation Principle to "extreme"

Providing that clients would typically consume just one method, though methods would be conceptually related, why not always apply the Interface Segregation Principle to the extreme and have [many] ...
Den's user avatar
  • 4,847
8 votes
1 answer
5k views

Is functional decomposition really an antipattern?

While I was reading The worst anti-patterns you have came across, I clicked on the link in this post to land on the web site about anti-patterns. And the http://sourcemaking.com/antipatterns/...
Coder's user avatar
  • 6,968
6 votes
4 answers
1k views

From a high level programming perspective, where does the 'different-paradigm' barrier between C# and F# really kick in?

I'm aware that they both use different programming paradigms, but from a high level perspective apart from differing syntax it seems most basic tasks can be achieved in similar fashion. I only say ...
FBryant87's user avatar
  • 323