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 ...
4
votes
3answers
118 views
Should databases be viewed as Monads?
Because any kind of persistence updates/inserts/deletes represents in some sense a kind of state change in a database, it makes me wonder whether databases can be considered monads. We say the same ...
2
votes
3answers
78 views
Declarative programming for deterministic real time control
Let's say you want control a motor in real time. Normally you would use a microcontroller or PC with e.g. c-programming language. So you would use an imperative approach. You tell the microcontroller ...
3
votes
1answer
75 views
Can I use maybe on multiple inputs in Haskell?
Suppose I wanted to test that both my inputs are positive. Can I do something like this?
test :: Float -> Float -> Maybe Float Float
test a b
| a>0 && b>0 = a b
| ...
-1
votes
0answers
167 views
What is mean by Lazy Code in c# [on hold]
I got an assignment in Functional Programming with C#. In this assignment there is a topic called lazy code. I've been searching for this topic for past two days now, and I have yet to come across any ...
7
votes
3answers
1k views
Is a function getting a value from another function considered pure?
I'm trying to figure out a way to handle default variable values when making functions without side effects and have ended up with the following:
function getDefaultSeparator() {
return ':';
}
...
-2
votes
0answers
21 views
How to generate a vector a functions in matlab? [on hold]
I am having trouble generating a vector of functions using a loop. My final go is to solve F(x) = 0 for a vector of functions, and each functions are different. I am using a loop to generate each ...
-1
votes
0answers
51 views
Which programming languages that support procedural, objected-oriented and functional paradigms are used the most? [closed]
I'm looking for popular multiparadigm programming languages that support:
-Procedural programming
-Objected-oriented programming
-Functional programming
Which are the most popular languages that ...
-2
votes
0answers
39 views
How does Elm know what UI to update?
Elm apps go by the following basic architecture
update : Action -> Model -> Model
Given a new model, how does Elm know which HTML needs updating? Does it refresh the entire UI with the new ...
9
votes
4answers
448 views
What programming problems do Monads solve? [closed]
I've read a lot of posts that explain what monads are, how unit and bind work, some of them plunging straight into category theory so abstract (for me at least) that makes the eyes bleed, some ...
10
votes
2answers
259 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 ...
53
votes
4answers
6k views
Is functional programming faster in multithreading because I write things differently or because things are compiled differently?
I'm diving into the world of functional programming and I keep reading everywhere that functional languages are better for multithreading/multicore programs. I understand how functional languages do a ...
2
votes
1answer
122 views
Enumerating the primitive recursive functions
How can I enumerate (by expression tree size, for example) all of the primitive recursive functions that map natural numbers to natural numbers in a traditional programming language like C?
For ...
1
vote
1answer
117 views
Why use tuples as function parameters in languages that support currying?
In languages that support currying, I can't think of many cases where using a tuple as function input parameters would be better than breaking the tuple apart into multiple parameters, which then ...
1
vote
0answers
55 views
Chronological/evolutionary positioning of Curry in relation to Haskell and Prolog
is Curry a transitional language from FP to Logic Programming (Haskell to Prolog), like Scala is a transitional language from imperative to FP (Java to Haskell)?
I find it hard to come up with a ...
-2
votes
1answer
211 views
Functional programming, and pushing item to array [closed]
I'm studying functional programming and I'm having some question concerning array population.
Actually, I'm trying to rebuild the Array.prototype.map function, and here's what I've got:
...
1
vote
2answers
99 views
Why does Scala name monadic composition as “for comprehension”?
Not sure if it's an appropriate question, but here it goes.
I know Haskell's do notation pretty well. And I realized that Scala's "for comprehension" really is just mostly the same as do notation in ...
4
votes
1answer
118 views
JavaScript functional conversion from flat list to tree
I've been going through the RxJS tutorials http://reactivex.io/learnrx/.
Almost all of the exercises involve moving from a hierarchical structure to a flat structure so I thought I'd try to do the ...
-1
votes
1answer
98 views
Does pure functional programming become agility impediment? [closed]
While I like benefits of strong typing system, there is one thing that worries me the most. I think of strong type system as means of forcing design choices. If a team builds a system unaware of its ...
0
votes
2answers
199 views
Is declarative programming overrated? [closed]
I've been programming for years with primarily-imperative languages (C++, C#, javascript, python), but have recently experimented with some functional langauges (Lisp, Haskell) and was excited to try ...
26
votes
10answers
3k views
Given a herd of horses, how do I find the average horn length of all unicorns?
The question above is an abstract example of a common problem I encounter in legacy code, or more accurately, problems resulting from previous attempts at solving this problem.
I can think of at ...
1
vote
4answers
250 views
Can objects be implemented in terms of higher order functions?
Martin Odersky finished one online course on Scala with an unanswered question:
Can we implement one concept in terms of other ?
Objects in terms of higher order functions?
Higher order functions ...
-2
votes
1answer
126 views
How do I create my own Objective-C to Swift converter? [closed]
I'm really interested in writing my own converter.
I know C++/Python/Objective-C/Swift and a little Haskell.
There are website like objectivec2swift and iswift.org, which can convert OC to Swift ...
8
votes
2answers
317 views
Workaround for implementing operations on doubly linked or circular data structures in languages with immutable data
I would like to learn how to make graphs and perform some local operations on them in Haskell, but the question is not specific to Haskell, and instead of graphs we may consider doubly linked lists.
...
14
votes
4answers
738 views
APIs and functional programming
From my (admittedly limited) exposure to functional programming languages, such as Clojure, it seems that encapsulation of data has a less important role. Usually various native types such as maps or ...
0
votes
1answer
105 views
Comparison Function Returns True or False
In my python CS class at school, we were given a true or false question as follows.
A comparison function returns either True or False.
When originally answering I thought about two things. ...
1
vote
3answers
236 views
Function Overloading in Python
My book says that function overloading is not possible in python but it asks me questions like:
WAP to find out the volume of a cube,cuboid and cylinder using function overloading.
Do I have to ...
5
votes
4answers
604 views
How does “repeat x = x:repeat x” return a list in Haskell?
This is supposed to return an infinite list of x's. However a list is created using an element, then the operator ':' and then a list.
The recursive definition of repeat' x = x:repeat' x seems to ...
17
votes
3answers
6k views
Why would I not need an ORM in a functional language like Scala?
I'm wondering if I can switch from Java to Scala in a Spring + Hibernate project to take advantage of some Scala features such as pattern matching, Option and what it seems to me a cleaner syntax in ...
4
votes
2answers
473 views
What are functional programmers using in place of UML?
I'm CS student. I am currently attending lectures, where we're taught Objective Analysis and Design. It consists mostly of writing use cases, analysing the problem that we can face when writing some ...
1
vote
1answer
403 views
Are the paradigms of ReactJS and Redux worthwhile for things other than web-development?
I'm a bit fascinated by the current paradigms shift libraries like ReactJs and Redux have caused in web development. Apart from computer science classes, I wasn't much affected by functional ...
7
votes
2answers
128 views
Is the Perl default variable like an FP monad?
I have been getting my head around monads in functional programming and seem to see some commonality between Perl's default variable $_ and FP monads.
Is this true? Are there similarities, if not ...
3
votes
3answers
110 views
Split a File into Multiple Objects Functionally
I want to read a file into a collection of objects. The data (it's a Leica PTX file if you're curious) is formatted as follows:
640 [begin item #1: number of columns]
480 [number of rows]
0 0 0 ...
15
votes
5answers
2k views
Is a function immediately impure if it takes a function as a parameter?
Since the purity of an input parameter is an unknown until runtime, is a function immediately considered impure if it takes a function as an input parameter?
Related: if a function applies a pure ...
1
vote
3answers
183 views
Functional programming: Compare all items in an array
In functional programming, how do I do an equality comparison of all items in an array?
I have an array of items that I want to compare, for example for equality. Is it possible to use a fold (also ...
4
votes
1answer
152 views
If Java allows immutable classes, then why cannot it be used as a functional language [closed]
I have been struggling with functional programming concepts for a while. I read that in functional programming, variable immutability is a fundamental thing. You don't change the state of a variable.
...
9
votes
2answers
1k views
Functional programming, compared to the process of a computer [duplicate]
In functional programming, it is considered bad practice (at least from my observations) to use state changes. Since computers operate in an imperative-language-like matter (performing one operation ...
2
votes
1answer
71 views
Time complexity of update and lookup in binary random access list
I'm trying to get through one of the exercises in Okasaki's "Purely Functional Data Structures," where he presents a zeroless binary numbers as a structure for random-access list, and asks to
9.6 ...
19
votes
2answers
401 views
How different is garbage collection in pure languages?
In a pure language like Haskell, all data is immutable and no existing data structures can be changed in any way. Additionally, many algorithms on immutable data and functional programming patterns ...
1
vote
2answers
499 views
Why do Haskell and Scheme use singly-linked lists?
A doubly linked list has minimal overhead (just another pointer per cell), and allows you to append to both ends and go back and forth and generally have a lot of fun.
3
votes
2answers
263 views
Shared data in functional programming
I have been working on a project in JavaScript which requires a data structure (read only), to be shared between two functions.
var mySharedData = ['hours', 'minutes', 'seconds'];
Now I have two ...
3
votes
3answers
324 views
How does Functional Programming's immutability feature work with CQS?
Given immutability (which is often encouraged and said to be one of building blocks of functional programming) and CQS (which says that commands should not return a value other than void/unit), how do ...
27
votes
5answers
3k views
What is it about functional programming that makes it inherently adapted to parallel execution? [duplicate]
I've been reading over and over that functional languages are ideal (or at least very often useful) for parallelism. Why is this? What core concepts and paradigms are typically employed and which ...
3
votes
2answers
662 views
Using 'reduce' vs 'for' loop for returning boolean [closed]
I was wondering what people think about using a reduce function vs loop for returning true if a condition exists.
Example:
var a = [1, 5, 7, 4, 2, 5, 3];
var greaterThan5 = a.reduce(function(prev, ...
4
votes
2answers
415 views
Can higher order functions ever be pure?
I was thinking about pure functions especially in the context of C++, which of course is not a purely functional language, and was wondering if higher order functions in C++ can ever be considered ...
6
votes
3answers
179 views
Why don't “multi-infinite” list comprehensions work with lazy evaluation?
As a simple demonstration of the efficiency of Haskell style, I thoughtlessly ran the following:
take 100 [(a, b, c) | a <- [1..], b <- [1..], c <- [1..], a^2 + b^2 == c^2]
This should be a ...
2
votes
2answers
382 views
Program like NASA?: Margaret Hamilton's Three Primitive Control Structures [closed]
On slide 19 in a presentation Margaret Hamilton describes three primitive control structures. My goal is to reduce the probability of errors in my code by working with this "design framework". I am ...
2
votes
1answer
131 views
Patterns for sharing context variables between functions
I am looking for ways of passing around a set of contextual variables that are required by functions.
As a Python programmer, right now I can see three ways of solving the problem: passing them ...
2
votes
2answers
247 views
Does function pointer have the same expressive power as function as parameter?
In functional programming language, a function can be passed as an argument to another function. In programming language like C/C++, a function pointer referring to a function can be passed to a ...
8
votes
3answers
267 views
Is the benefit of the IO monad pattern for handling side effects purely academic?
Sorry for yet another FP + side effects question, but I couldn't find an existing one which quite answered this for me.
My (limited) understanding of functional programming is that state/side effects ...
8
votes
4answers
346 views
Is there a Haskell idiom for trying several functions and stop as soon as one succeeds?
In Haskell, I can use the type a -> Maybe b to model a function that either returns a value of type b, or returns nothing (it fails).
If I have types a1, ..., a(n+1) and functions f1, ..., fn, ...