All Questions
Tagged with functional-programming functions
29 questions
10
votes
5
answers
8k
views
How to name a function that returns a function?
Let's say, for example, that I have a function makeFoo that makes another function foo:
function makeFoo(string) {
return () => string
}
const foo = makeFoo('bar');
I know that makeFoo is a ...
-1
votes
1
answer
215
views
Why is it called a functional component?
A quick google search shows that the question I have has not been asked directly, and so I ask it here. For what its worth, I am learning react, and I come from a C++ background, where as far as I ...
6
votes
1
answer
724
views
What's the benefit of avoiding partial functions in Haskell?
AFAIK in Haskell it is heavily recommended to avoid partial functions; and if these seem unavoidable (eg head) then return a Maybe. At least, so the Haskell wiki says 1 2
What's the use of the ...
1
vote
1
answer
315
views
Python - Paradigm to compute different formulas with the same function
I have different equations to compute the same quantity. For example, val = my_func(a, b, c) but also val = my_func(x, y), where my_func represents the quantity I would like to compute: it could be ...
12
votes
2
answers
5k
views
A real-life example of using curry function? [closed]
I was struggled to find a real-life example of using curry function and get the benefit of using curry.
When I google curry function I often see the example like
let add = x => y => x + y;
let ...
4
votes
2
answers
297
views
Function that returns non parameter functions
I found a function in c# like this:
private Dictionary<string, Func<string>> ObtenerExtraCfgCampo(MsgDefCamp camp)
{
var extra = new Dictionary<string, Func<string>&...
4
votes
1
answer
3k
views
Naming conventions for pure functions
Are there 'conventions' / best practices on naming pure functions?
For example:
adding numbers: add or sum?
calculating the square root: calcSqrt or sqrt?
reversing a list: reverse or reversed?
...
1
vote
1
answer
120
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
1
answer
1k
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 ...
17
votes
6
answers
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 ...
9
votes
3
answers
3k
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
1
answer
559
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
1
answer
877
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 ...
8
votes
2
answers
976
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 ...
2
votes
2
answers
419
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 system of ...