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)

-1
votes
1answer
17 views

Frame pointer left out of stack frame?

I have a question in relation to control abstraction Under what circumstances can the frame pointer be left out of the stack frame Is this a stack overflow error? or could this be caused by ...
5
votes
1answer
96 views

Functional core for elevator system design

How can Gary Bernhardt's "Functional Core / Imperative Shell" architecture be used to design software for an elevator system? Specifically, let's say there are a few elevators, each with call buttons ...
1
vote
0answers
140 views

What are the types of tasks for which Functional Programming paradigm really wins over imperative one? [closed]

During its evolution C# gradually gets more and more features which belong to functional paradigm. Subjectively these features allow (at least me) to be more productive, fluent and write maintainable ...
17
votes
4answers
2k views

What are the benefits of referential transparency to a programmer?

In programming, what are the benefits of referential transparency? RT makes one of the major differences between functional and imperative paradigms, and is often used by advocates of the functional ...
1
vote
0answers
33 views

Clojure: Decomposing Logging, Metrics, and Business Logic from a Function

I was reading the post A Modern Architecture for FP that included a code snippet that the author wanted to decompose further. I don't know Haskell but I recognize enough to know that I've written many ...
4
votes
1answer
72 views

Scala Callback Pyramid of Doom

I would like to solicit some general design principles and best practices to avoid creating a callback pyramid of doom particularly in the Scala language. Consider the following rudimentary and ...
3
votes
1answer
220 views

Is a trace table useful in functional programming?

A trace table is a technique used to test algorithms. "The table usually takes the form of a multi-column, multi-row table; With each column showing a variable, and each row showing each number ...
4
votes
1answer
127 views

In the context of functional programming, what are 'total' functions and 'partial' functions?

I'm not finding via Google any explanation that my brain can grasp. Can someone explain this, and if possible, give an example of each using either pseudocode or C#? The term 'total' function was ...
19
votes
4answers
3k views

Functional style exception handling

I've been told that in functional programming one is not supposed to throw and/or observe exceptions. Instead an erroneous calculation should be evaluated as a bottom value. In Python (or other ...
25
votes
5answers
1k views

Does catching/throwing exceptions render an otherwise pure method impure?

The following code examples provide context to my question. The Room class is initialized with a delegate. In the first implementation of the Room class, there are no guards against delegates that ...
5
votes
1answer
130 views

Is anything gained by making dependencies explicit via function argument lists when implementing pure methods?

This question is followup to this question. Is there any benefit in avoiding the 'this' operator when implementing pure methods? That is, are there any advantages to making all dependencies explicit ...
20
votes
5answers
592 views

How to model a circular reference between immutable objects in C#?

In the following code example, we have an class for immutable objects that represents a room. North, South, East, and West represent exits into other rooms. public sealed class Room { public Room(...
2
votes
6answers
559 views

Function creating function, compiled languages equivalent

I'm new to compiled languages. I'm learning C. I'm used to coding in python. I was wondering if there was any equivalent, or replacement method in compiled langues for functions able to create a ...
-4
votes
1answer
51 views

In internal computer memory Char value ,string and integer how they differentiate time of storing and retrieving

In internal computer memory Char value ,string and integer how they differentiate time of storing and retrieving . Char A =ASCI value 127 Int value 127 Binary is same then how computer ...
0
votes
1answer
120 views

Is there a name for this kind of function?

I'm a data analyst, not a software developer, and I often find myself writing a function like this (shown in Python syntax here): def apply_many(arg, *funcs): return [func(arg) for func in funcs] ...
91
votes
3answers
13k views

Why do Trampolines work?

I've been doing some functional JavaScript. I had thought that Tail-Call Optimization had been implemented, but as it turns out I was wrong. Thus, I've had to teach myself Trampolining. After a bit of ...
5
votes
1answer
210 views

What does “the standard stateless functional view of algorithms” mean?

From Kelvin Murphy's review on Algorithms (4th Edition) by Sedgewick and Wayne For data structures, it is obviously natural to use classes, but they also adopt this approach for many algorithms, ...
0
votes
3answers
138 views

Is it possible to reason about memory just by looking at type signatures?

If I have pure functional programming language with* very very smart optimization* proccess, is it possible to reason about memory usage, just by looking at type signature? add :: Int -> [Int] -&...
4
votes
3answers
217 views

Naming convention for functions which have side effects? [closed]

I heard somebody say their language has a convention where the names of functions which mutate state must end with an exclamation point. I'm trying to write more functional code and I like the idea of ...
4
votes
1answer
165 views

Are generator functions valid in functional programming?

The questions are: Do generators break the functional programming paradigm? Why or why not? If yes, can generators be used in functional programming and how? Consider the following: function * ...
1
vote
1answer
78 views

When/how is it okay to redefine/declare variables? [functional]

I've been learning functional programming in javascript of late, and there's one thing that's been confusing me. I can't quite understand if it's ever okay to redefine variables. Something like: a = ...
2
votes
2answers
157 views

When to use tail recursion?

I've recently gotten into functional programming. I asked a question earlier over here "'Remembering' values in functional programming" and learned a lot of things I hadn't even realized I wanted to ...
3
votes
1answer
87 views

Can event emitters be functional?

For instance, array.map accepts a callback that returns a value. const newArray = oldArray.map(item => doSomethingTo(item)); Promises also accept callbacks that return a value. const ...
19
votes
4answers
4k views

“Remembering” values in functional programming

I've decided to take upon myself the task of learning functional programming. So far it's been a blast, and I've 'seen the light' as it were. Unfortunately, I don't actually know any functional ...
2
votes
2answers
148 views

Simulated functional programming in C — passing the entire program state as a function argument

I have a struct called State which holds all the variables for the program. Rather than being modified by functions directly, it is the value returned. Here is some code: #define USERNAME_LENGTH 20 #...
4
votes
1answer
91 views

Why the name MailboxProcessor in F#?

It seems that the standard practice is to immediately alias MailboxProcessor<'T> to Agent<'T>. So why the name in the first place anyways? Why don't they just call it Agent<'T>, if ...
2
votes
1answer
62 views

Pure functions and the outer scope [duplicate]

Excuse my ignorance, I come from the C family of languages but zero exposure to functional languages. I've read that pure functions only generate output based on a given input. Same input gives the ...
8
votes
4answers
549 views

Do non-OOP paradigms support concepts such as encapsulation?

One of the important concepts in Object Oriented Programming is Encapsulation. However, lately the software world seems to be tilting in favour of other paradigms like functional programming. It ...
0
votes
1answer
93 views

Functional reactive ideomatic 'OR' function

I'm would like to know your opinion of what is an ideomatic way writing a OR function in functional reactive programming. That is, if I have x number of signals which can return a truthy or falsy ...
2
votes
2answers
127 views

Unknown number of arguments in currying

Hypothetical situation - can a currying function have an unknown number of arguments (kind of like varargs) Eg in Python: addByCurrying(1)(2)(3)(4) Should equal 10 addByCurrying(5)(6) Should ...
1
vote
1answer
106 views

What are the factors that prevent wider adoption of languages with dependent types?

While there are/were several languages with dependent types, like Agda, Coq or Epigram, none seemed to gain wider adoption. Despite that dependent types allow very strong type safety, up to writing ...
2
votes
2answers
79 views

Concerns on lazy evaluation and infinite data structures

I am trying to learn how lazy evaluation works because I'm going to implement try to implement it in the programming language I'm developing (I know it isn't the best thing to do (to try to implement ...
0
votes
0answers
33 views

Reducing a list into a Map of ranges

I have nested structures that record ranges. The sub-structure record sub-ranges. For example: [ { type: "A", start: 0, end: 2, ...otherInfo, sub: [ { type: "B", ...
2
votes
2answers
134 views

Designing the recursive solution

I understand the recursion and find it useful and intuitive while solving problems on trees but for many other problems recursion never fails me to leave puzzled. Recently I was solving the following ...
0
votes
1answer
78 views

What is the difference between Applicative and Generative Modules, and Type Classes?

Reading the comments to this blog post made me realize I don't know much about some really interesting functional mechanisms between languages like Haskell, OCaml and Standard ML. I'd love a high-...
3
votes
1answer
225 views

What is the functional programming method for combining two “streams” of data?

I'm trying to figure out what the appropriate way to deal with this problem is in a functional way. I'm assuming there's a functional data structure or technique that will make this easy to handle. ...
1
vote
2answers
203 views

Simulating objects in Functional Programming

In FP vs. OO, from the trenches, Michael Fogus says: Whenever I write some code to deal with data about people then functional programming seems to work best. Whenever I write some code to ...
2
votes
1answer
73 views

Preserving log of immutable Data Structure changes

I have large and complex immutable data structure (language is F#, but should be applicable to any language really) where I defined a lot of functions making changes and returning new instances of ds ...
2
votes
2answers
132 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 ...
1
vote
0answers
64 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 ...
6
votes
1answer
135 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 ...
1
vote
1answer
74 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
97 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 ...
4
votes
3answers
174 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 ...
6
votes
4answers
741 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 ...
3
votes
2answers
132 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 ...
2
votes
0answers
66 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 ...
1
vote
1answer
152 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 ...
0
votes
2answers
157 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 ...
5
votes
1answer
309 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 ...