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
56 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 ...
4
votes
8answers
627 views

One-use variables - has any language ever had them?

A principle that I follow is that, when an identifier is established, it should be a signal to the reader that the value referred to is indeed an abstraction which will be used more than once. That ...
23
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 ...
40
votes
11answers
9k 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 ...
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 ...
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 ...
-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: ...
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 ...
22
votes
4answers
3k views

Is return-type-(only)-polymorphism in Haskell a good thing?

One thing that I've never quite come to terms with in Haskell is how you can have polymorphic constants and functions whose return type cannot be determined by their input type, like class Foo a ...
1
vote
2answers
191 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, ...
2
votes
2answers
176 views

Haskell types for functions

I don't understand the answer to this question: Q: Can Haskell find a type for the function selfapply defined by: selfapply f = f f A: The function selfapply is not typeable in the simple ...
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, ...
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
87 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 ...
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
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 ...
4
votes
1answer
548 views

Local Updates in Persistent/Immutable Data Structures

I'm getting into ReactJS and am intrigued but also confused about persistent data structures. I love the idea, but I'm not sure how to take my MV*, Mutable, Observable Bindings experience in designing ...
32
votes
6answers
8k views

Workaround for Java checked exceptions

I appreciate a lot the new Java 8 features about lambdas and default methods interfaces. Yet, I still get bored with checked exceptions. For instance, if I just want to list all the visible fields of ...
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. ...
4
votes
2answers
1k views

How is intermediate data organized in MapReduce?

From what I understand, each mapper outputs an intermediate file. The intermediate data (data contained in each intermediate file) is then sorted by key. Then, a reducer is assigned a key by the ...
1
vote
4answers
232 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 ...
4
votes
1answer
754 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) { ...
9
votes
1answer
4k views

C++11 support for higher-order list functions

Most functional programming languages (e.g. Common Lisp, Scheme / Racket, Clojure, Haskell, Scala, Ocaml, SML) support some common higher-order functions on lists, such as map, filter, takeWhile, ...
-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 ...
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 ...
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
94 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 ...
8
votes
5answers
2k views

A programming language that does not allow IO. Haskell is not a pure language

Are there any 100% pure languages (as I describe in the Stack Overflow post) out there already and if so, could they feasibly be used to actually do stuff? i.e. do they have an implementation? I'm not ...
35
votes
8answers
11k views

Is Functional Programming possible in Java? [closed]

I was browsing through the Amazon.com Bookstore and I came across the book "Functional Programming for Java Developers". I know some very basic Functional Programming and have been programming in ...
38
votes
1answer
4k views

Why (or why not) are existential types considered bad practice in functional programming?

What are some techniques I might use to consistently refactor code removing the reliance on existential types? Typically these are used to disqualify undesired constructions of your type as well as 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
418 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
239 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 ...
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 ...
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 ...
62
votes
2answers
10k views

What is the “Free Monad + Interpreter” pattern?

I've seen people talking about Free Monad with Interpreter, particularly in the context of data-access. What is this pattern? When might I want to use it? How does it work, and how would I implement ...
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 ...
25
votes
3answers
3k views

How is dependency inversion related to higher-order functions?

Today I've just seen this article which described the relevance of SOLID principle in F# development- F# and Design principles – SOLID And while addressing the last one - "Dependency inversion ...
32
votes
3answers
3k views

Why is an anemic domain model considered bad in C#/OOP, but very important in F#/FP?

In a blog post on F# for fun and profit, it says: In a functional design, it is very important to separate behavior from data. The data types are simple and "dumb". And then separately, you ...
4
votes
5answers
1k views

Java memory management (thunks/lazyness)

If I want to create an infinite list of integers in Java like so: ArrayList<Integer> list = new ArrayList<Integer>(); for(int i = 0;;i++){ list.add(i); } I run out of memory. My ...
9
votes
6answers
2k views

Can functional programming be used to develop a full enterprise application?

I am just beginning to learn Functional programming (FP). I come from a OOP world, where everything are objects, and most of them are mutable. I have a hard time wrapping around the concept that ...
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 ...
35
votes
6answers
15k views

What is the difference between a function and a lambda?

I'm a little bit confused about 'function' and 'lambda'. I've seen some examples showing that the scheme keyword lambda works very similarly to the JavaScript keyword function, but I really don't ...
5
votes
2answers
628 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 ...
44
votes
14answers
5k views

Why the current enthusiasm for Functional Programming? [closed]

I've been hearing a lot of enthusiasm about functional programming languages lately, with regards to Scala, Clojure, and F#. I've recently started studying Haskell, to learn the FP paradigm. I love ...
16
votes
5answers
9k views

Performance: recursion vs. iteration in Javascript

I have read recently some articles (e.g. http://dailyjs.com/2012/09/14/functional-programming/) about the functional aspects of Javascript and the relationship between Scheme and Javascript (the ...
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. ...
5
votes
1answer
649 views

PHP Aspect Oriented Design

This is a continuation of this Code Review question. What was taken away from that post, and other aspect oriented design is it is hard to debug. To counter that, I implemented the ability to turn ...