Skip to main content

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
79 votes
10 answers
17k views

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 ...
Fireburn's user avatar
  • 889
1 vote
2 answers
423 views

Some programming languages allow conditional value assignments that look like x = (IF condition THEN a ELSE b) My search-fu is failing me: how do we call such statements in the jargon of ...
Deleplace's user avatar
  • 143
3 votes
1 answer
200 views

My aim is to create a language specific to the scientific field (which would be used mainly in the field of machine learning and physics) which would be based on the functional paradigm, a paradigm ...
Foxy's user avatar
  • 621
5 votes
2 answers
470 views

I'm currently reading "Composing Software" by Eric Elliott, which is about functional programming in JavaScript. He states that if you compose multiple functions together, and that these ...
user1474326's user avatar
1 vote
1 answer
126 views

I've encountered the infomral definition of foldr in a couple of books. I've attached an image from Bird and Wadler's "Introduction to Functional Programming" (1988), but I've seen the same ...
Sarel's user avatar
  • 41
5 votes
3 answers
736 views

I feel this is a bad question because I probably do not understand what I am talking about. In my effort to learn about functional programming, I became stumped on understanding the idea of immutable ...
Julian's user avatar
  • 77
4 votes
3 answers
1k views

I often use function closures for storing data (e.g. database URL), which doesn't change between function calls. Is this an (anti-)pattern? Does it have a name? While developing apps, which recieve ...
Sebastian DonnerWolfBach's user avatar
10 votes
4 answers
2k views

I'm learning about "Functional Core, Imperative Shell" as espoused by Gary Bernhardt in his talk about "Boundaries". In reality, it seems like these ideas have been known for a ...
Maletor's user avatar
  • 209
16 votes
10 answers
7k views

I think the answer to the first part of my question is, "yes" -- no point in making objects immutable in a single-threaded application (or I guess in a multi-threaded application if that ...
releseabe's user avatar
  • 539
-1 votes
1 answer
242 views

background: so, I am working on an NLP problem. where I need to extract different types of features based on different types of context from text documents. and I currently have a setup where there is ...
ultron's user avatar
  • 109
0 votes
2 answers
333 views

Following Martin Odersky's course on coursera - Functional Programming with Scala and I'm on Week 4 where we're learning about Types and Pattern Matching. In the video lecture, this is the ...
Saturnian's user avatar
  • 157
3 votes
1 answer
620 views

If I am writing in a functional style and want to use the Replace Conditional with Composition refactoring pattern on a switch or a long chain of if/else if/else if/..., how do I approach it? I ...
jinglesthula's user avatar
0 votes
2 answers
230 views

The Elm Guide says to use Maybe for partial functions, but I was under the impression that returning Maybe solves the problem of partial functions and makes them total. It gives a value from the ...
bcb's user avatar
  • 119
1 vote
3 answers
284 views

The question pretty much says all, but let's look into a simple example (I'm using C++, but the question is not strictly related to any particular language): So, let's say that we have a functor that ...
cyau's user avatar
  • 137
10 votes
5 answers
9k views

Let's say, for example, that I have a function makeFoo that makes another function foo: function makeFoo(string) { return () => string } const foo = makeFoo('bar'); I know that makeFoo is a ...
Splox's user avatar
  • 209
1 vote
4 answers
734 views

Given a scenario where you have consecutive setters or a series of events where an object is modified, can it be more performant to instead write code in a way where a new state is returned rather ...
artman41's user avatar
  • 129
2 votes
2 answers
841 views

When I'm writing code in the form of IO Monad, I wonder what's real value of it.For example I have a function as def something(in: In): IO[Out]; my function is a pure function that **returns an impure ...
tweetingReza's user avatar
0 votes
1 answer
234 views

I was reading the Urbit docs and stopped at this paragraph (emphasis mine): The main thing to understand about our ‘overlay OS’, as we call it, is that the foundation is a single, simple function. ...
Paul Razvan Berg's user avatar
1 vote
4 answers
927 views

I have been experimenting with the idea of function classes as explained in this article and Composition applied to function dependencies as described in the following questions: https://stackoverflow....
user32882's user avatar
  • 267
5 votes
3 answers
433 views

Apply is a fitting name for a member function of a function-type class that applies the function to the given arguments: class Addition { int apply(int a, int b) { return a + b; } } But ...
kutschkem's user avatar
  • 530
38 votes
7 answers
9k views

Encapsulation In object-oriented programming (OOP), encapsulation refers to the bundling of data with the methods that operate on that data, or the restricting of direct access to some of an ...
Christopher Trotter's user avatar
9 votes
4 answers
4k views

I'm a .Net and Angular developer who's been working with OO languages throughout my education and work history. Lately I've been thinking about spending some time with one of the functional ...
human17's user avatar
  • 425
1 vote
1 answer
372 views

Recently I have asked this question: How do you rewrite the code which using generics and functionals in Java 8 and mixing oop and functional programming by using only object-oriented? on ...
Taha Yavuz Bodur's user avatar
3 votes
1 answer
701 views

From what I understand, the visitor pattern is supposed to solve the expression problem (described here), where a program needs to support performing multiple operations on multiple types, ideally ...
DylanSp's user avatar
  • 327
7 votes
1 answer
7k views

For modelling software implemented with the imperative or procedural programming paradigm we have Flowcharts, process diagrams, etc. For object oriented we have UML class diagrams, object diagrams, ...
Pillqu's user avatar
  • 107
3 votes
3 answers
250 views

I am not sure if I ever clearly understood standard corollary "what to solve" and "how to solve" used to point out difference between functional (declarative) and imperative programming paradigm ...
rahulaga-msft's user avatar
-3 votes
2 answers
159 views

Let's say, that we keep track of students entering the auditorium using their IDs(Key) and their check-in time(Value) in a Map. We delete the entries once they move out of the auditorium. I want to ...
Vicky's user avatar
  • 399
2 votes
2 answers
425 views

Bartosz Milewski, in his book "Category Theory for Programmers" says that: Composition is associative. If you have three morphisms, f, g, and h, that can be composed (that is, their objects match ...
SeeR's user avatar
  • 139
5 votes
3 answers
3k views

I'm planning an empirical study on function passing - specifically lambdas aka anonymous functions aka arrow functions. Now, although functional or even object-oriented approaches are highly favored ...
Nils Mehlhorn's user avatar
2 votes
0 answers
76 views

I am learning about MV* architectural patterns, thanks to the help from several answers here. I learned that they are used for designing the architectures of user interactive applications. I also ...
Tim's user avatar
  • 5,565
-2 votes
3 answers
612 views

I have been struggling to understand programming paradigms. OOP is a paradigm with sole aim of modeling complex (real-world) systems, and it got me thinking: is OOP the only programming paradigm ...
LekeOpe's user avatar
  • 271
1 vote
3 answers
453 views

I have been using c# and trying to learn FP. In context of FP I often hear that usage of basic assignment or return statements are not considered composable, hence their usage is not advised in FP ...
rahulaga-msft's user avatar
2 votes
3 answers
119 views

Question about OO-programming, functional programming, NoSQL, SQL databases, and software architecture Hi all, I am a intermediate-level self-taught programmer, and have been dying to get an answer ...
troglodyte's user avatar
10 votes
2 answers
890 views

I understand what pure functions are and when someone says pure functions are composable - I believe it means that the output of one function can be passed as an input to another function but same ...
rahulaga-msft's user avatar
5 votes
5 answers
634 views

OOP makes state reads and writes implicit. For instance, in Python: class Foo: def bar(self): # This method may read and/or write any number of self.attributes. # There is no way ...
Dun Peal's user avatar
  • 159
1 vote
1 answer
239 views

In my work I frequently come across systems of interdependent equations. I have contrived a toy example as follows. The terminal values w, x, y and z are given: e(y) = A+B A(y) = x*log(y)+y^z B(y) =...
user32882's user avatar
  • 267
1 vote
1 answer
486 views

Redux uses a state reducer pattern where essentially you create a pure function that looks like: function reducer (previousState, action) { //... return newState; } This looks similar to ...
dwjohnston's user avatar
  • 2,769
-1 votes
1 answer
226 views

A quick google search shows that the question I have has not been asked directly, and so I ask it here. For what its worth, I am learning react, and I come from a C++ background, where as far as I ...
Anon's user avatar
  • 3,649
6 votes
1 answer
752 views

AFAIK in Haskell it is heavily recommended to avoid partial functions; and if these seem unavoidable (eg head) then return a Maybe. At least, so the Haskell wiki says 1 2 What's the use of the ...
gaazkam's user avatar
  • 4,529
-1 votes
3 answers
217 views

When everything seems to be a collection, how do you enforce rules for members of said collection without the use of an interface? As far as I am aware, in languages that don't fully support OOP ...
coolpasta's user avatar
  • 657
4 votes
0 answers
613 views

I am writing module that other people can use in their code. It's a calendar. I want to allow users to set locale parameter so that they have month names and other data in language of their choice. ...
psycat's user avatar
  • 141
1 vote
1 answer
183 views

I have a set of pure functions that can be composed almost trivially in a pipe as initialValue -> [f] -> [g] -> [h] -> ... -> [m] -> [n] -> [o] -> outputValue The problem I ...
pob's user avatar
  • 119
0 votes
1 answer
127 views

I'm thinking about a structure like this. cardGame: players: - john: hand: - card: id: 1 suit: diamond ...
Nina Reynolds's user avatar
-1 votes
1 answer
124 views

So I have the feeling that one can forget object oriented programming when reactive streams are in use, due to the lack of the async-await syntax (because with the call chaining, the state has to be ...
zeller's user avatar
  • 161
6 votes
3 answers
482 views

In the company in which I work, it is customary to model entities using Interfaces when developing with Typescript. To me, it seems much more effective to model entities with classes and then ...
noam steiner's user avatar
5 votes
1 answer
2k views

I've written my first moderately large project in functional style (in F#) and can see the advantages. The main challenge was to achieve the "Onion" architecture i.e. large and "smart" pure core / ...
KolA's user avatar
  • 645
1 vote
1 answer
353 views

I have different equations to compute the same quantity. For example, val = my_func(a, b, c) but also val = my_func(x, y), where my_func represents the quantity I would like to compute: it could be ...
Davide_sd's user avatar
  • 147
0 votes
1 answer
325 views

I am new to functional programming and I can't find a function like reduce to build an AgreggateRoot given an EventStream: List.reduce ((aggregate, event) -> aggregate) eventList As I understand ...
Leonardo Mangano's user avatar
8 votes
3 answers
3k views

To the best of my understanding Monads were created to allow for composing functions with those that had potential side-effects - loosely speaking. For me composition implies code like so: f(g(h(x)))...
PhD's user avatar
  • 2,541
1 vote
2 answers
377 views

For a long time, the use of these Monad structures has been restricted to a very small circle of languages, many of them purely functional (mainly due to problems related to the management of the IO). ...
Jack Rock's user avatar

1
2
3 4 5
15