Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
1 vote
1 answer
120 views

Private types, units of measure when is it a good idea?

My question is regarding using private type in F#. Consider the case we have some application and we have some library. One may consider using units within the library, and making them private behind ...
user avatar
  • 111
1 vote
2 answers
129 views

Should I add functionality by adding a new method to a class - or should I "register" the new functionality into a data structure?

I have one large class that computes ~50 different metrics (each metric has no side effects). My code is similar to this: class ReportingMetrics: def __init__(self, data:pd.DataFrame, config:dict)...
user avatar
  • 195
1 vote
0 answers
82 views

Terse finite state machines in Haskell

I'm writing a parser for a markup language in haskell, and a finite state machine fell out of my ideal API. I have code that looks a bit like this: Token = BoldWord String | Word String | ...
user avatar
  • 281
0 votes
1 answer
125 views

How to test a function with several conditional nested side effects

In Python, consider a function like the following: def main(*args): value1 = pure_function1(*args) if condition(value1): value = side_effect1(value1) if value: ...
user avatar
  • 109
4 votes
2 answers
252 views

Should I use classes instead of functions with a state needed for computation?

I have implemented the cows and bulls game in C++. The code: #include <cstdio> #include <cstdlib> #include <ctime> struct DigitMatches { int matches_in_right_positions; int ...
user avatar
  • 51
0 votes
2 answers
103 views

How to convert vehicle schedule time window calculation algorithm to FP

I am working on an algorithm that optimizes utilitization of a vehicle. What I have is a list of paths the vehicle is planned to take and between which times (time windows) it has to be at a certain ...
user avatar
11 votes
6 answers
3k views

Is ad-hoc polymorphism a good practice in functional programming?

I am developing a utils data engineering package in python, and for the sake of reusability and readability, I chose the functional programming (FP) approach. Assume a key task of converting data from ...
user avatar
  • 221
1 vote
2 answers
138 views

Connecting classes by passing method references

I am trying to find a good way of allowing two objects that are separated by a intermediate object to communicate while keeping the architecture loosely coupled. A solution I have developed is to pass ...
user avatar
  • 21
1 vote
0 answers
87 views

How to improve maintainability and testability of a service by refactoring it into a functional style

A customer of ours has a rather large (500+ LOC) service as central part of the project. Written in C# and consisting of rather clunky large imperative style functions, I was asked to improve the test ...
user avatar
1 vote
3 answers
100 views

How to model a time-distributed process in functional programming style?

I'm searching for any formal/generic approach to modeling a process distributed in time with functional programming. Here is an example. Let's implement a very simple notification service. It accepts ...
user avatar
  • 149
0 votes
2 answers
387 views

Should "functional core, imperative shell" approach canonically break "don't test private methods" rule?

In short, "functional core, imperative shell" can be summarized as: functional core implements logic; you unit test it. Your tests call real functions just like in production real functions ...
user avatar
-1 votes
1 answer
64 views

Design suggestions for my simple data-analysis program

I need to create a program with the purpose of cross-referencing personal info from a spreadsheet(s), to check for conflicts of interest between clients of 3 different law firms. All of this client ...
user avatar
  • 99
-1 votes
1 answer
66 views

Appropriate base type for simply typed lambda calculus

Given the following hypothetical programming language: Intended for practical programming A simply typed lambda calculus (STLC) All objects are functions, based on Church encodings I am aware that ...
user avatar
5 votes
2 answers
2k views

Database access with functional programming

I'm interested in becoming more familiar with functional programming as a paradigm, so I'm trying to introduce a more functional style to some of my projects. I'm struggling to understand how to ...
user avatar
  • 305
30 votes
3 answers
5k views

Definition of "functor"; Haskell vs. C++

I'm trying to understand whether the Haskell and C++ communities mean different things by the word "functor", or if there's some underlying concept that unifies the two meanings. My ...
user avatar
76 votes
10 answers
15k 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 ...
user avatar
  • 859
1 vote
2 answers
167 views

What is the name of "an IF-ELSE expression that returns a value"? [closed]

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 ...
user avatar
  • 143
3 votes
1 answer
109 views

Choosing the design of a scientific DSL: purely or impurely functional?

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 ...
user avatar
  • 219
5 votes
2 answers
281 views

Doesn't "Always test through the public interface" contradict testing of individual composed functions?

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 ...
user avatar
1 vote
1 answer
89 views

Unclear as to the informal definition of foldr

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 ...
user avatar
  • 41
5 votes
3 answers
607 views

How could a computer program do anything if everything is immutable?

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 ...
user avatar
  • 77
4 votes
3 answers
590 views

Is this extensive usage of closure a known (anti-)pattern? And does it have a name?

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 ...
user avatar
7 votes
3 answers
533 views

Functional architecture with lots of I/O

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 ...
user avatar
  • 179
16 votes
10 answers
6k views

Are immutable objects important only in multi-threaded applications and if so, how are shared immutable objects useful?

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 ...
user avatar
  • 517
-1 votes
1 answer
107 views

Refactoring: Pythonic way of reducing the subclasses?

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 ...
user avatar
  • 109
-1 votes
2 answers
160 views

Trying to understand how this class representation truly represents Natural numbers in Scala

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 ...
user avatar
  • 147
3 votes
1 answer
223 views

Applying Replace Conditional with Composition in functional programming

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 ...
user avatar
0 votes
2 answers
150 views

Is a safe function returning Maybe partial or total?

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 ...
user avatar
1 vote
3 answers
195 views

Is it a good practice for functors to store outputs as instance attributes?

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 ...
user avatar
  • 137
6 votes
5 answers
3k views

What do you call a function that returns a function?

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 ...
user avatar
  • 169
1 vote
4 answers
662 views

Can writing Object-Orientated Code in a Functional style improve performance?

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 ...
user avatar
  • 129
-5 votes
1 answer
45 views

Choosing 2 or 3 values out 3 values after calculating their closeness

I want to find a specific algorithm to choose either 2 or 3 out of 3 given values. Like if I have a set of values 10,11,12 all three are close enough so I will calculate the mean of the value and ...
user avatar
1 vote
2 answers
323 views

What's the value of IO Monad?

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 ...
user avatar
0 votes
1 answer
187 views

What does it mean for an OS to compile down to a function?

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. ...
user avatar
1 vote
4 answers
394 views

Design pattern for a function class

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://...
user avatar
  • 213
5 votes
3 answers
283 views

What should a member function be called that applies an argument function to the object?

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 ...
user avatar
  • 332
36 votes
7 answers
9k views

Do you need to think about encapsulation if you can ensure immutability?

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 ...
user avatar
9 votes
4 answers
2k views

Functional programming - what to learn and who uses it

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 ...
user avatar
  • 387
1 vote
1 answer
177 views

Is designing a generic parameterized class with methods of it accepting higher order functions a functional technique that we can use in Java 8?

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 ...
user avatar
2 votes
1 answer
341 views

Does the visitor pattern prevent the need to modify existing code when adding new data types?

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 ...
user avatar
  • 225
5 votes
1 answer
2k views

Is there a UML diagram for functional programming?

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, ...
user avatar
  • 87
3 votes
3 answers
199 views

Precisely define "what to solve" and "how to solve" corollary in functional and imperative programming respectively

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 ...
user avatar
-3 votes
2 answers
110 views

How can we handle inserts/delete cases using Map like data structures in FP?

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 ...
user avatar
  • 399
0 votes
2 answers
229 views

Example of NOT associative (not composable) function

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 ...
user avatar
  • 119
5 votes
3 answers
3k views

Significant difference between functional and procedural collection handling [closed]

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 ...
user avatar
2 votes
0 answers
58 views

Do MV* architectural patterns apply not only to OO languages but also functional languages?

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 ...
user avatar
  • 5,271
-2 votes
3 answers
336 views

Do functions make Java a functional programming language? [closed]

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 ...
user avatar
  • 261
1 vote
3 answers
324 views

what it means when someone says - "statements/instructions are not composable"?

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 ...
user avatar
2 votes
3 answers
100 views

How should I best structure my app when I want to sort a "parent" model by a property computed on another "child" model?

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 ...
user avatar
9 votes
2 answers
666 views

Why are impure functions said to be non-composable?

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 ...
user avatar

1
2 3 4 5
15