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

learn more… | top users | synonyms (1)

2
votes
2answers
108 views

Nested functions: should I explicitly pass arguments or rely on scope?

Suppose I have a function f that uses two helper functions h and g to get the job done. There are two possible ways of dealing with this situation. (1) take explicit arguments and returns new objects ...
0
votes
0answers
17 views

Algorithm to generate all paths between two vertices of a graph in F#

Following a functional programming approach (no mutable data structures, recursion, etc) I have written a script in F# to generate all paths between two vertices of an undirected, unweighted graph. I ...
3
votes
0answers
42 views

How do you model has-a (aggregation) relationships in functional programming languages

Just to be on the same terms: Aggregation is a has-a relationship, where the owned components can exist independently of the owning component.E.g. a pond and some ducks swimming in it. A duck leaving ...
42
votes
8answers
24k views

What is a “side effect?”

I haven’t clearly understood the concept of side effect. What is side effect in programming? Is it programming language dependent? Is there such a thing as external and internal side effects? ...
11
votes
4answers
8k views

Is the Entity Component System architecture object oriented by definition?

Is the Entity Component System architecture object oriented, by definition? It seems more procedural or functional to me. My opinion is that it doesn't prevent you from implementing it in an OO ...
12
votes
2answers
345 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 ...
14
votes
6answers
8k views

Which self balancing binary tree would you recommend?

I'm learning Haskell and as an exercise I'm making binary trees. Having made a regular binary tree, I want to adapt it to be self balancing. So: Which is most efficient? Which is easiest to ...
46
votes
12answers
6k 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 ...
1
vote
1answer
62 views

What is the connection between type inference and advanced type systems?

I don't understand the connection between type inference and advanced type systems. I don't see why Haskell or Standard ML or OCaml could not have existed without type inference. My only guess is that ...
1
vote
1answer
95 views

How do you organize your hoisted functions?

In a module (file) I organize several functions related to a specific domain task. I usually put the function linearly from top to bottom, then compose a functional call on the bottom. Doing so I can ...
5
votes
4answers
568 views

Minimal programmer's definition of a monad

I am trying to formulate a definition of a monad without needing mathematical terms or Haskell to understand. Can a monad be thought of as a function that accepts a value and wraps it such that it ...
4
votes
3answers
136 views

How are typeclasses in functional languages different from interfaces in OO languages?

I'm learning about paradigms of functional languages. So I've read that while Subtype polymorphism is typical for OO languages, Parametric polymorphism is typical for functional languages. But I ...
4
votes
4answers
391 views

Why it is `(cons 1 (cons 2 (cons 3 nil)))` and not `(cons 3 (cons 2 (cons 1 nil)))` for [1,2,3]?

Is there any special reason that to construct list in Scheme you use (cons 1 (cons 2 (cons 3 nil))) instead of (cons 3 (cons 2 (cons 1 nil))) ? While the first seems more obvious because it ...
2
votes
2answers
114 views

What is the most idiomatic way to iterate collection with different action for first element?

Sometimes we meet a situation where we should iterate (or map) over a collection, applying the same procedure (function) for all elements except the first one. The simplest example is finding the max ...
13
votes
5answers
1k views

Why are cons lists associated with functional programming?

I have noticed that most functional languages employ a singly-linked list (a "cons" list) as their most fundamental list types. Examples include Common Lisp, Haskell and F#. This is different to ...
2
votes
0answers
59 views

Elements of structure in a functional program

In object oriented, we have requirements, use cases, and UML which can form a nice conceptual framework. The goal there, is to define objects, their responsibilities, behaviors and communications ...
0
votes
2answers
140 views

How do you deal with a mutable buffer in a functional space?

I have a stream parsing method in C# that reads portions of a protocol frame from the STOMP protocol; the specification isn't the important part for the question though. What is important is that I ...
1
vote
1answer
112 views

Functional Programming in PHP

Modern PHP is mostly written Object Oriented. Other than the fact that there is inertia towards the Object Oriented in the PHP community, is there anything about the language itself that would make it ...
16
votes
6answers
4k views

A language based on limiting amount of arguments passed to functions

The idea is inspired by the fact operators such as +, -,%, etc. can be seen as functions with either one or two arguments passed, and no side-effects. Assuming I, or someone else, writes a language ...
15
votes
9answers
2k views

What would be good factual arguments to convince high level management to consider functional programming? [closed]

There are tons of "theoretical" arguments for why functional programming is a Good idea (too many for that to have stayed as an open question, and correctly so). However, most of them are arguments ...
5
votes
1answer
268 views

How to move from OOP object composition to FP function composition in C#

I have been working for a few weeks on a new web project and I am realizing that all I am doing is basically calculations and transformations on data, and that most of my classes do not contain any ...
3
votes
1answer
127 views

Are promises functional

Functional programming is often explained to agree with lazy evaluation. As far as I know lazy evaluation means that a method gets called if the evaluator/browser/etc. thinks that is the next best ...
7
votes
2answers
265 views

What is a Comonad and how are they useful?

Recently I've been dusting off my knowledge on how Monads work. I've also been introduced to the concept of a 'Comonad', which is described as the inverse of a monad. However, I am impossible to wrap ...
18
votes
3answers
3k 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?
7
votes
5answers
1k views

What makes functional programming languages declarative as opposed to Imperative?

On many articles, describing the benefits of functional programming, I have seen functional programming languages, such as Haskell, ML, Scala or Clojure, referred to as "declarative languages" ...
7
votes
2answers
168 views

Data structure for two-dimensional board games in Functional languages

I am creating a simple MiniMax implementation in the functional programming language Elixir. Because there are many perfect-knowledge games (tic tac toe, connect-four, checkers, chess, etc), this ...
0
votes
2answers
115 views

Advantages of workflow based software development vs normal programming based software development

I am very new to workflows, and trying to understand why workflows are used. While surfing internet, I haven't found any strong point for using workflows. Please explain me the scenarios where ...
6
votes
0answers
243 views

What lambda function optimizations, if any, are planned for Java 9 and beyond?

I'm working on a high-performance project where Java 8's lambda functions are enormously useful. I've found, however, that they're memory inefficient when used en masse. For example, suppose I need to ...
2
votes
1answer
96 views

Programatically determine that some functions are pure

I saw this question that shows it is impossible to programatically determine if a javascript function is pure, but is it sometimes possible to affirm that a function is pure - so something like... ...
4
votes
0answers
114 views

Does it make sense to apply the principles in Redux to OO languages?

Redux is essentially functional programming, and it makes a lot of sense. As I move back to a non-javascript OOP language in a different project I would like to apply the same principles such as ...
27
votes
3answers
5k 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, ...
6
votes
3answers
967 views

How Does The Maybe Monad Relate To The Option Type?

I was doing a presentation on F# and was discussing the Option type when someone in the audience asked me if the Option type is F#'s implementation of the maybe monad. I know that's not the case but ...
5
votes
0answers
82 views

How does the Free monad and Reactive Extensions correlate?

I come from a C# background, where LINQ evolved into Rx.NET, but always had some interest in FP. After some introduction to monads and some side-projects in F#, I was ready to try and step to the next ...
1
vote
2answers
46 views

Type of map for Try[T]

I was looking at the type of map for Try[T] in Scala, which is: def map[S](f: T=>S): Try[S] From Haskell, I am used to the type of map being: map :: (a->b)->[a]->[b] This seems very ...
3
votes
2answers
138 views

Referential Transparency by using Zero References?

Referential Transparency is one of the corner stones of functional programming that allows us to apply equative reasoning to our code. However it does so at a cost to performance, by use of immutable ...
14
votes
5answers
435 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 ...
4
votes
2answers
92 views

Under what scenarios would 'functional' `Try` objects be more or less beneficial than 'rx' `Try` objects?

Definitions used by this question: 'functional' Try is what https://github.com/lambdista/try is. Success and Failure are subclasses of Try. Exceptions aren't thrown by the called function. 'rx' Try ...
51
votes
12answers
9k 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 ...
2
votes
2answers
582 views

Why isn't functional programming embraced more widely? [duplicate]

Possible Duplicate: Why isn't functional programming more popular in the industry? Does it catch on now? I've been working as a J2EE developer for the past 3 years and wanted to learn ...
5
votes
4answers
798 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] ...
40
votes
10answers
7k 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? ...
0
votes
2answers
146 views

Almost point-free style

Programmers often talk about point-free style. In contrast to the imperative style (pseudocode): h := function(x) { y := f(x) z := g(y) return z; } one might write the following point-free: ...
16
votes
2answers
2k views

Does Clojure have continuations/coroutines/etc?

I started programming with Python, and I was really confused by concepts like coroutines and closures. Now I think I know them on some superficial level, but I've never felt that "enlightement" ...
2
votes
1answer
74 views

Term for the opposite of the functional Compose operator

In functional programming, given a function f and a function g we can define a function . (compose): let (.) f g = fun x -> g (f x) Is there a term for the function which applies arguments in the ...
34
votes
7answers
4k views

What do you call a function that's pure, meaning 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 ...
26
votes
1answer
1k views

How to implement a branch-and-bound in a functional programming language?

I am trying to write a branch and bound search on the set of all functions f: D -> R, where the domain size is small (|D| ~ 20) and the range is much bigger (|R| ~ 2^20). Initially, I came up with the ...
2
votes
6answers
250 views

How does immutability remove the need for locks when two threads are trying to update the shared state?

Okay so I read through this: Does immutability entirely eliminate the need for locks in multi-processor programming? And this was the main takeaway for me: Now, what does it get you? ...
45
votes
13answers
12k 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 ...
5
votes
2answers
124 views

Using queues to decouple functions/avoid direct calling?

Kind of a functional programming newbie question here: I've been reading the transcripts of some of Rich Hickey's talks, and in several of his more well-known ones, he recommends using queues as an ...
2
votes
4answers
528 views

What is Big-O notation for purely functional languages?

Is it still relevant? Instead of var result = new List<int>(); for (var i = 0; i < prev.Count; ++i) { result.Add(prev[i] * 2); } where the result.Add, prev[i], and * 2 instructions ...