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 ...
0
votes
3answers
97 views
Why python function programming functions are not collection methods? [duplicate]
In other words, is there a Python design related reason for it to be so?
Functions like map, filter, reduce etc. are just plain functions.
Is it just a poor design choice (if it is a good one, ...
6
votes
0answers
101 views
Maintaining State without assignment
I am learning functional programming and I have trouble understanding how some particular scenarios are implemented without the use of assignment. The following simple problem pretty much sums up my ...
0
votes
1answer
137 views
Advantages of the imperative style over the functional style [duplicate]
There's a lot of hype over functional languages right now, and I've spent the last year studying Haskell as my intro to FP as a result. Seeing the advantages FP provides is easy (such as referential ...
4
votes
1answer
134 views
Pattern matching against two similar types
What is the best way to handle pattern matching in the following situation?
sealed trait Metadata
final case class Metadata1() extends Metadata
final case class Metadata2() extends Metadata
final ...
0
votes
0answers
30 views
Accessing intermittently available resources with transactions and post-access cleanup in a generalized, functional, composable way
The following psuedo-code illustrates what I'd like to be able to do. Is there a way to accomplish something like this in Scala?:
trait IntermittentlyAvailableResource
trait ...
0
votes
1answer
65 views
FP: Capturing the characteristics of a process which blocks, causes side-effects, and may fail
I have a driver function modifyFile that interacts with many sources in the outside world (e.g. HTTP, filesystem). Let's say the code is as such:
def downloadFile(from: String, to: String): Try[Unit]
...
11
votes
2answers
302 views
Is higher-rank parametric polymorphism useful?
I'm pretty sure everyone is familiar with generic methods of the form:
T DoSomething<T>(T item)
This function is also called parametrically polymorphic (PP), specifically rank-1 PP.
Let's ...
11
votes
3answers
3k 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.
...
6
votes
0answers
135 views
Is it common practice to transform requirement specifications into predicate logic for functional programming?
I've recently been assigned to work on a small project which is being implemented in Haskell. Coming from an OO/imperative background, I'm used to converting requirements/user-stories into use-cases ...
0
votes
0answers
89 views
What is the relationship between “flux” and pure functional reactive programming?
Flux, as far as I understood, is a technique about dealing with the dataflow of an application unidirectionally, keeping state isolated from the rest of the program in read-only, self-contained ...
5
votes
3answers
438 views
Is Functional Programming a viable alternative to dependency injection patterns?
I have recently been reading a book entitled Functional Programming in C# and it occurs to me that the immutable and stateless nature of functional programming accomplishes similar outcomes to ...
2
votes
1answer
77 views
FP and board game state
I wanted to implement the game of Tic Tac Toe using a functional language (in my case, Scala) but I'm unsure how to go about managing the board game state after each player makes their move.
I ...
1
vote
1answer
115 views
Functional Programming style: How to write functions - explicit currying, implicit currying or lamdas?
So I have been using F# for a while and studying a bit of Haskell on the side and I have realized I could rewrite the exact same function one of three different ways.
Either with implicit currying, ...
-1
votes
2answers
199 views
Is functional language without runtime written in C possible?
Every functional language that compiles to native code relies on quite big runtime written in C programming language (well at least ones that I know of, for example Haskell, OCaml, Gambit/Chicken ...
-1
votes
1answer
67 views
Significance of '__name__ ' attribute in python
1)
Below python code,
>>> def f():
return
creates a function type object which has __name__ attribute with value 'f' which looks fine.
But,
2)
Below line of code,
>>> x = ...
5
votes
3answers
790 views
Can “higher order function” feature allow/maintain abstraction and encapsulation?
Below is the function repeat written using a functional paradigm, such that when called as repeat(square, 2)(5) it will apply the square function 2 times on the number 5, something like ...
1
vote
0answers
87 views
How and where to make global function file in jsp sevlet web application
I am making a website in Servlet&JSP. I am looking for good way to make a specific function file from where I can call and declare my common functions. If I made a java file function. Java, so is ...
-4
votes
4answers
129 views
Does this python program obey functional paradigm?
Below is the hailstone sequence program considering the rule of thumb in functional programming.
The simple rule of thumb is: if you can replace any expression, sub-expression or subroutine call ...
4
votes
1answer
106 views
How would I isolate changes to mutable state if I need to run two queries to get the final result?
I'm working on some code that takes search criteria from a Rest API and uses it to query a remote API to return results. As an exercise, I wanted to try to separate all state changes to one place, as ...
1
vote
1answer
116 views
How do I enforce 'referential transparency' in this program?
Below is the python program written to follow the rule of thumb in functional programming.
The simple rule of thumb is: if you can replace any expression, sub-expression or subroutine call with ...
0
votes
1answer
100 views
Abstracted better? Data driven string creation
I am trying to post this question neutral of programming language so it helps the widest audience. But for those who must know, I am using Objective-C and iOS frameworks.
The background:
I have a ...
0
votes
1answer
54 views
Dealing with error in data - Idempotent approach
A prior question had an answer that interested me from a design perspective. I work in geospatial data and occasionally have to deal with voids when I read these binary files into my product. What is ...
16
votes
6answers
1k views
Does functional programming increase the 'representational gap' between problems and solutions? [closed]
Since machine language (e.g., 0110101000110101) computer languages have generally evolved to higher forms of abstraction, generally making it easier to understand the code when it's applied to a ...
0
votes
1answer
52 views
Choose approaches for updating an object
Say I have a simple object created by from user input:
var input = { url: 'http://example.com/', path: 'abc', user: 'adam' };
And I am to write function(s) that update url and path properties ...
2
votes
1answer
97 views
How to make an interpreter for a stack of Free Monad Transformers
I like the idea of using Free monads to "purify" code and I've used it in some simple scenarios. However, I can't seem to figure out how to write an interpreter for a Free monad transformer. In ...
6
votes
1answer
161 views
Is the use of DSLs in a state monad a good approach to building complex stateful computations?
First, sorry if that title makes no sense. I am a little out of my depth here with the terminology.
So, imagine that I'm writing a text editor in Haskell. For the purposes of this question, let's ...
0
votes
1answer
174 views
What kind of reputation does Java 8 have among “enterprise” companies? [closed]
Are the new, functionally-inspired features of Java 8 well-regarded within the enterprise development community? Have they been adopted by large companies? Have coding standards been updated to ...
14
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 ...
2
votes
3answers
206 views
Declaring lambdas in Java8
What would be the best practice to declare lambdas in Java8 code? How it was designed to be used?
For example, let's say that we have a method that accept a Function. I want to provide function ...
18
votes
1answer
1k views
Confusion between F# and C# [duplicate]
I am fairly new to functional programming and C#/F#.
What is unclear to me is: Can you do functional programming in C# and/or in F#?
Or is it something like, you write some OO code in C#, and some FP ...
2
votes
2answers
328 views
Should we refactor our existing codebase to use functional programming, especially streams? [closed]
We have a large project written in PHP. It almost exclusively uses imperative operations, as in example 1. Should we refactor our existing code to use functional operations? Do you think that the code ...
4
votes
1answer
203 views
Functional programming for loop side effect
I am trying to get my head around as to why having a local variable or a for loop inside a function is not considered to be pure functional programming.
Given this function:
int as_int(char *str)
{
...
1
vote
4answers
399 views
Is it possible to use functional paradigm in imperative languages?
If I understand the concept correctly the goal, which functional languages are trying to achieve is to eliminate any side effects from functions and to eliminate a state. The rationale behind this is ...
-1
votes
1answer
82 views
New DDD, context-oriented, functional… approach in building business layer [closed]
We are building some business modules that must be intuitive for developers to use, so the code itself explains and forces developers to use it in certain way. This applies both for enhancing the ...
13
votes
1answer
464 views
What is Banana split and fusion in functional programming?
These terms got mentioned in my university course. Quick googling pointed me to some university papers, but I am looking for a simple explanation.
2
votes
1answer
278 views
In what way are union types better for correctness than a common interface?
I've just recently started familiarising myself with functional programming, mostly via F#, and there's one particular functional idiom that I'm not fully understanding the benefits of. I've seen it ...
0
votes
1answer
164 views
Programming CPU Emulator Functional Style [closed]
I want to write an 8086 CPU emulator in javascript, functional style.
How would one conceptualise / design an 8086 emulator, or any CPU emulator that has registers and realmode memory access in a ...
10
votes
5answers
597 views
Why do functional programs have a correlation between compilation success and correctness?
I've been trending toward functional programming for 4 years now, ever since I first started working with LINQ. Recently, I wrote some pure functional C# code and I noticed, first hand, what I've ...
2
votes
3answers
200 views
What do I use for a variant in a UML class diagram?
Does standard UML specify how a variant (aka tagged union, discriminated union, sum type, etc) should be depicted in a class diagram?
2
votes
1answer
272 views
Is the application architecture of Facebook Flux a new idea?
Facebook announced that it's using the architecture they call Flux to develop their projects.
It consists of a single direction dataflow, and concepts like a Dispatcher, Stores and Actions (well ...
0
votes
3answers
233 views
Reference counting & GC in LISP [closed]
What is the main method for reclaiming the memory in LISP? Does LISP really need garbage collection? Would not reference counts suffice?
I just wanted to know whether reference counts are enough ...
0
votes
1answer
140 views
How to Understand the concept of Immutablity in Functional Programming [duplicate]
I have come across several sources that say that immutability is a concept that is followed in functional programming. I have come across this concept when looking at collections in Scala where a new ...
3
votes
0answers
174 views
Lightweight data modeling vs traditional classes [closed]
I've heard a lot of talk about using lightweight data modeling as of late. Especially in relation to the Clojure programming language. What is it and how it differs from traditional classes regarding ...
1
vote
1answer
195 views
What was the influence of Chris Okasaki's data structures on Scala? [closed]
I heard a friend say:
The first real use of Chris Okasaki's book was in Clojure's data structures
I heard another friend say:
No, they influenced the design of Scala in quite a subtle way.
...
3
votes
6answers
943 views
How can IO cause side effects in Functional Programming? [duplicate]
Whenever I read about Haskell, I find that IO can cause side effects.
But I do not understand how it would do it?
Do we mean that we are writing to a file from one lazy sequence and another lazy ...
11
votes
5answers
2k 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 ...
1
vote
3answers
381 views
Help me to understand 'stateless' software in functional programming
I'm an experienced software engineer, and have experience in a range of languages from PHP, Ruby, C#, Java - the last few years I've primarily worked in Java.
I'm now learning Scala, and it's my ...
5
votes
2answers
377 views
Alternative to language purity
Purity
One of the interesting concepts in Haskell is the purity. However, I am wondering what the pragmatic reasons behind this is - let me explain a bit more before you reject my question.
My main ...
2
votes
0answers
94 views
What makes the functional and logic programming paradigms well suited for programming AI? [duplicate]
I have been researching different programming paradigms. I have found a lot of people saying that one of the areas where logic and functional programming are particularly good is programming AI, but I ...
3
votes
1answer
308 views
How to avoid global state without large function signatures?
So, there are some good answers to this question, namely:
Why is Global State so Evil?
I have a specific question about the alternatives Mikera proposed as the answer with the second most up-votes. ...