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
0answers
59 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 ...
2
votes
1answer
106 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 ...
0
votes
0answers
52 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
199 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: ...
2
votes
2answers
78 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 ...
3
votes
1answer
88 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
93 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
161 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
11answers
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
233 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
96 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
309 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
716 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
95 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
223 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
596 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 ...
16
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
419 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
243 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
106 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 ...
13
votes
4answers
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
175 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 ...
3
votes
1answer
150 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
65 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
389 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
418 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.
2
votes
1answer
124 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
319 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
2k 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
612 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
379 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
173 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
379 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
119 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
226 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
254 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 ...
7
votes
4answers
334 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, ...
1
vote
1answer
185 views

The difference between bind and _.curry

So JavaScript's bind supports currying, but most people use some other library like lodash or ramda to do currying. From first impression It seems like bind supports context changing, since that is ...
5
votes
2answers
178 views

What is the difference between currying and partial function application in practice

I understand the difference between partial function application and a curried function (f(X x Y x Z) -> N vs f(X -> (Y -> (Z -> N)))), but I do not see what the consequence of this ...
31
votes
2answers
1k views

What is the meaning of “doesn't compose”?

I see a lot of texts, especially functional programming texts, claim that certain CS concepts "don't compose". Examples are: locks don't compose, monads don't compose. I've been having a hard time ...
2
votes
2answers
117 views

Is the function using python list comprehension, stateless?

Below is the function count_leaf, that appends mutable list branch_counts, which is not stateless. def count_leaf(tree): if is_leaf(tree): return 1 branch_counts = list() for b in ...
0
votes
0answers
67 views

How to ensure this constraint at compile time?

I have an interesting constraint/invariant and I would love to hear people's input on how to maintain it. Big bonus if it can be ensured at compile time... I have the types below, and the following ...
1
vote
2answers
148 views

What is the advantage of global functions when writing functional code

I am a Swift developer and am trying to adopt a functional / reactive style in my code. I have been using ReactiveCocoa in all my projects and I have started giving RAC 3.0 a try. One thing I have ...
1
vote
3answers
160 views

Using delegates to avoid duplicate creation of resources

I'm writing a PCL that uses an HttpClient to go visit a few sites and extract data from them. My initial code looked like this: public static class Download { public async static ...
3
votes
0answers
110 views

How to handle complex calculated fields in an ORM

In our API we've got a few central datatypes which need to be "decorated" (so to speak) after retrieval from the database with calculated values. The database is accessed through an ORM which follows ...
2
votes
2answers
366 views

How do I make this functional DSL written in an imperative language more efficient?

Suppose I create a simple functional Domain-specific language (DSL) using an imperative language, in this case C++. Here is a simple implementation of a DSL that can has the notion of a simple value ...
15
votes
3answers
2k views

What problem do algebraic data types solve?

Fair warning, I'm new to functional programming so I may hold many bad assumptions. I've been learning about algebraic types. Many functional languages seem to have them, and they are fairly useful ...
14
votes
5answers
1k views

Is the semantic contract of an interface (OOP) more informative than a function signature (FP)?

It is said by some that if you take SOLID principles to their extremes, you end up at functional programming. I agree with this article but I think that some semantics are lost in the transition from ...