People who code: we want your input. Take the 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
7
votes
3answers
687 views

How is arrow operator an Applicative Functor in Haskell?

Note: Still learning Haskell, not reached Monoids, studying Applicative Functors. I saw this implementation and I am not entirely clear on it: instance Applicative ((->) r) where pure x = (\...
4
votes
1answer
672 views

functional programming with mutating request object

Following uses JavaScript code but F# is tagged for input from functional programmers. I understand that in functional programming we shouldn't mutate the state or incoming parameters but I'm ...
4
votes
1answer
1k views

When should I create my own @FunctionalInterface rather than reuse the interfaces defined in java.util.function?

The functional interfaces in java.util.function cover the vast majority of common strategies one might want to apply, but it's also possible to define your own @FunctionalInterface instead. In cases ...
18
votes
3answers
3k views

How do the type systems in functional languages differ from those in OO languages? [duplicate]

I keep reading stories from developers who state that once they are able to get the FP programs written in languages like Haskell, Ocaml, Elm and even Rust, to compile without errors, they are pretty ...
0
votes
1answer
330 views

Why isn't it common to hack partial function application in C#?

In many ways C# supports functional programming, but there is a (shrinking) list of features commonly found in statically-typed functional languages that are missing, such as tail recursion, partial ...
3
votes
2answers
201 views

functional programming: impact of typedef-ing datatypes on code readability and maintenance

In functional programming languages, such as Scala, data types and structures, are really important. I am in two minds about the use of type-defs in helping with the readability of the code ...
21
votes
4answers
9k views

Should functions that take functions as parameters, also take parameters to those functions as parameters?

I often find myself writing functions that look like this because they allow me to easily mock data access, and still provide a signature that accepts parameters to determine what data to access. ...
5
votes
0answers
435 views

FRP-style GUIs in Java

I recently built a small web application using riotjs, a library that facilitates creating UIs in the spirit of functional reactive programming, i.e. defining the UI as a pure function of the ...
5
votes
2answers
1k views

Are all deterministic functions free of side-effects (and vice versa)?

I'm reading about pure-functions in functional programming and am wondering, whether a function being deterministic implies that the function is also side-effect free? (and vice versa?)
1
vote
1answer
189 views

Can I, Should I, How do I refactor for vuex - redux?

We need to get more much more rigorous about managing state in our business application. The heart of our problem is an object, lets call it an "TaxRefundApplication", that has about 20 properties, ...
4
votes
1answer
375 views

What are some practical uses of Generalized Algebraic Datatypes? [closed]

All tutorials on GADTs that I've seen (in Haskell, Coq and Idris) use one same exapmle of a well-typed interpreter to show how GADTs can be useful, where you use the type index to encode the type of ...
4
votes
2answers
445 views

What are the correct functional programming terms for what I'm doing here?

I recently needed a function to deep clone an object. I started with the code given as an accepted answer to this question: https://stackoverflow.com/a/728694/1253156 However, our SonarQube ...
1
vote
2answers
1k views

Functional programming, Domain Driven Design, and Test/Behavior Driven Development

I am posting because, first of all, I want to make sure my understanding on these 3 methodologies is correct. Secondly, I would like some clarification on how they could all fit in together. I see ...
9
votes
2answers
698 views

How can I _read_ functional JavaScript code?

I believe I have learned some/many/most of the basic concepts underlying functional programming in JavaScript. However, I have trouble specifically reading functional code, even code I've written, and ...
4
votes
2answers
736 views

Java8: why two composition methods: andThen and compose?

As a beginner in both java8 and functional programming, I think I'm missing something when reading about function composition since I cannot find a reason why there are two methods that do this, ...
3
votes
1answer
676 views

Why Functional Programming - When is it okay to get rid of efficiency for readability?

I was reading Death of for-loop article, and I thought maybe I should timeit the codes. I created this benchmark at jsperf which clearly shows that map-filter approach is about 90% slower. So, why is ...
3
votes
1answer
678 views

Should I pass all arguments to a method explicitly in functional programming?

I wonder whether a method in a functional programming language should receive all variables from the argument list, or whether it is ok to use variables from the outer scope? But let me explain the ...
5
votes
2answers
637 views

Can an Impure Function be Referentially Transparent?

Is a total, impure function considered to be Referentially Transparent (RT)? Example: // Given an 'id', try to retrieve an optional Person // from the database, i.e. side-effect. // Note that '...
2
votes
2answers
3k views

Multiple arguments vs a tuple argument

In functional languages without type checking, is there any substantial disadvantage (apart from readability) to limiting all functions to take exactly one argument - that is, replacing multi-argument ...
4
votes
3answers
886 views

What is the core philosophy of functional programming? [closed]

I come from an object oriented programming background, therefore, I am pretty curious about the core philosophy of functional programming? Why does it exist at the first place, and what types problems ...
10
votes
1answer
1k views

How does functional style helps with mocking dependencies?

From the interview with Kent Beck in a recent Java Magazine issue: Binstock: Let’s discuss microservices. It seems to me that test-first on microservices would become complicated in the sense that ...
2
votes
0answers
180 views

combine reader monad with choice

I have this two types open FSharpx open FSharpx.Reader type First = { Name: string Items: string list } type Second = { Name: string Numbers: int list } Using a Reader monad ...
-1
votes
1answer
60 views

Need Help to build a Custom Notification read logic for Individual user basis

I'm building a custom Notification section, which provides notification or messages to multiple users on any particular object update, I've created a HTML page like Dashboard where I have added a ...
2
votes
1answer
93 views

F# - Associating a function with the matching type of object

Let's say I'm programming a chess game. At some point I have to check, which moves are valid for a given piece. What would be the proper way to select the correct pathfinding function for a given ...
5
votes
3answers
459 views

Mutability and objects; how to properly manage data?

Objects tend to confuse me some. In understand the concept and use, certainly, but I feel like the functional paradigm is somewhat restricting my use of them. At the moment, I'm creating a simple ...
21
votes
5answers
3k views

What is the benefit of having “no runtime errors”, like Elm claims?

Some languages claim to have "no runtime errors" as a clear advantage over other languages that has them. I am confused on the matter. Runtime error is just a tool, as far as I know, and ...
4
votes
1answer
307 views

Can heavy use of the service pattern substitute pure functions without losing benefits?

There are huge benefits to pure functions in functional programming, but can the same benefits be obtained in imperative programming with heavy use of the service pattern? I ask because I want to ...
5
votes
1answer
521 views

Functional core for elevator system design

How can Gary Bernhardt's "Functional Core / Imperative Shell" architecture be used to design software for an elevator system? Specifically, let's say there are a few elevators, each with call buttons ...
1
vote
0answers
285 views

What are the types of tasks for which Functional Programming paradigm really wins over imperative one? [closed]

During its evolution C# gradually gets more and more features which belong to functional paradigm. Subjectively these features allow (at least me) to be more productive, fluent and write maintainable ...
18
votes
4answers
4k views

What are the benefits of referential transparency to a programmer?

In programming, what are the benefits of referential transparency? RT makes one of the major differences between functional and imperative paradigms, and is often used by advocates of the functional ...
3
votes
0answers
363 views

Clojure: Decomposing Logging, Metrics, and Business Logic from a Function

I was reading the post A Modern Architecture for FP that included a code snippet that the author wanted to decompose further. I don't know Haskell but I recognize enough to know that I've written many ...
4
votes
1answer
591 views

Scala Callback Pyramid of Doom

I would like to solicit some general design principles and best practices to avoid creating a callback pyramid of doom particularly in the Scala language. Consider the following rudimentary and ...
2
votes
1answer
652 views

Is a trace table useful in functional programming?

A trace table is a technique used to test algorithms. "The table usually takes the form of a multi-column, multi-row table; With each column showing a variable, and each row showing each number ...
10
votes
1answer
7k 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 ...
26
votes
4answers
7k views

Functional style exception handling

I've been told that in functional programming one is not supposed to throw and/or observe exceptions. Instead an erroneous calculation should be evaluated as a bottom value. In Python (or other ...
28
votes
5answers
3k views

Does catching/throwing exceptions render an otherwise pure method impure?

The following code examples provide context to my question. The Room class is initialized with a delegate. In the first implementation of the Room class, there are no guards against delegates that ...
4
votes
1answer
219 views

Is anything gained by making dependencies explicit via function argument lists when implementing pure methods?

This question is followup to this question. Is there any benefit in avoiding the 'this' operator when implementing pure methods? That is, are there any advantages to making all dependencies explicit ...
26
votes
5answers
3k views

How to model a circular reference between immutable objects in C#?

In the following code example, we have an class for immutable objects that represents a room. North, South, East, and West represent exits into other rooms. public sealed class Room { public Room(...
2
votes
6answers
745 views

Function creating function, compiled languages equivalent

I'm new to compiled languages. I'm learning C. I'm used to coding in python. I was wondering if there was any equivalent, or replacement method in compiled langues for functions able to create a ...
-7
votes
1answer
98 views

In internal computer memory Char value ,string and integer how they differentiate time of storing and retrieving

In internal computer memory Char value ,string and integer how they differentiate time of storing and retrieving . Char A =ASCI value 127 Int value 127 Binary is same then how computer ...
0
votes
2answers
233 views

Is there a name for this kind of function?

I'm a data analyst, not a software developer, and I often find myself writing a function like this (shown in Python syntax here): def apply_many(arg, *funcs): return [func(arg) for func in funcs] ...
107
votes
3answers
15k 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 ...
6
votes
1answer
711 views

What does “the standard stateless functional view of algorithms” mean?

From Kelvin Murphy's review on Algorithms (4th Edition) by Sedgewick and Wayne For data structures, it is obviously natural to use classes, but they also adopt this approach for many algorithms, ...
0
votes
3answers
244 views

Is it possible to reason about memory just by looking at type signatures?

If I have pure functional programming language with* very very smart optimization* proccess, is it possible to reason about memory usage, just by looking at type signature? add :: Int -> [Int] -&...
12
votes
3answers
3k views

Naming convention for functions which have side effects? [closed]

I heard somebody say their language has a convention where the names of functions which mutate state must end with an exclamation point. I'm trying to write more functional code and I like the idea of ...
19
votes
1answer
3k views

Are generator functions valid in functional programming?

The questions are: Do generators break the functional programming paradigm? Why or why not? If yes, can generators be used in functional programming and how? Consider the following: function * ...
1
vote
1answer
762 views

When/how is it okay to redefine/declare variables? [functional]

I've been learning functional programming in javascript of late, and there's one thing that's been confusing me. I can't quite understand if it's ever okay to redefine variables. Something like: a = ...
3
votes
2answers
1k views

When to use tail recursion?

I've recently gotten into functional programming. I asked a question earlier over here "'Remembering' values in functional programming" and learned a lot of things I hadn't even realized I wanted to ...
6
votes
1answer
1k views

Can event emitters be functional?

For instance, array.map accepts a callback that returns a value. const newArray = oldArray.map(item => doSomethingTo(item)); Promises also accept callbacks that return a value. const ...
20
votes
4answers
6k views

“Remembering” values in functional programming

I've decided to take upon myself the task of learning functional programming. So far it's been a blast, and I've 'seen the light' as it were. Unfortunately, I don't actually know any functional ...

1 2 3
4
5
15