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 ...
3
votes
1answer
84 views
In the context of functional programming, what are 'total' functions and 'partial' functions? [duplicate]
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 ...
17
votes
4answers
2k 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 ...
22
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 ...
-2
votes
0answers
37 views
Project scope and functional requirements [closed]
What is the difference between Scope and Functional requirements of a software project (With example). How is scope written(In paragraph or list of modules)?
5
votes
1answer
123 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 ...
17
votes
3answers
383 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(...
1
vote
6answers
549 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
115 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 ...
-2
votes
0answers
54 views
WebAPI in c# using a functional paradigm
I am building a WebAPI in c# and would like to use a more functional programming style. I understand that using a functional language would be better but thats not a option at the moment. Looking ...
5
votes
1answer
182 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
136 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
202 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
136 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
74 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
155 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 ...
1
vote
1answer
62 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
144 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
88 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
61 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
542 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
92 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
115 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
104 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
122 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
73 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
219 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
200 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
59 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
134 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
73 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
171 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
716 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
129 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
65 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
149 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
153 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
306 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 ...
16
votes
6answers
4k views
A language based on limiting amount of arguments passed to functions
The idea is inspired by the fact operators such as +, -,%, etc. can be seen as functions with either one or two arguments passed, and no side-effects. Assuming I, or someone else, writes a language ...
3
votes
1answer
260 views
Are promises functional
Functional programming is often explained to agree with lazy evaluation.
As far as I know lazy evaluation means that a method gets called if the evaluator/browser/etc. thinks that is the next best ...
7
votes
2answers
356 views
What is a Comonad and how are they useful?
Recently I've been dusting off my knowledge on how Monads work. I've also been introduced to the concept of a 'Comonad', which is described as the inverse of a monad. However, I am impossible to wrap ...
7
votes
2answers
264 views
Data structure for two-dimensional board games in Functional languages
I am creating a simple MiniMax implementation in the functional programming language Elixir. Because there are many perfect-knowledge games (tic tac toe, connect-four, checkers, chess, etc), this ...
0
votes
2answers
166 views
Advantages of workflow based software development vs normal programming based software development
I am very new to workflows, and trying to understand why workflows are used. While surfing internet, I haven't found any strong point for using workflows.
Please explain me the scenarios where ...