All Questions
Tagged with functional-programming function
621 questions
1
vote
1
answer
64
views
How to automatically detect and decurry a curried function at Runtime?
I am working with curried functions in TypeScript, and I want to figure out a way to automatically detect if a function is curried and, if it is, decurry it into a non-curried function.
Problem:
A ...
1
vote
1
answer
59
views
Motivating pure functions: are all pure functions commutative in execution order?
I’m trying to understand whether all pure functions are commutative with respect to execution order. That is, does the order in which pure functions are executed ever matter, assuming no external ...
0
votes
0
answers
38
views
Are Jsonnet variables the same as functions with no parameters?
Are Jsonnet variables, the ones that end with a semicolon (as opposed to the ones that end with a comma), the same as functions with no parameters?
In the following Jsonnet program
{
c: local a = ...
1
vote
1
answer
51
views
Referential transparency of Jsonnet functions
The Jsonnet Language Reference has this to say about Jsonnet functions:
Functions in Jsonnet are referentially transparent, meaning that any function call can be replaced with its definition, without ...
1
vote
1
answer
56
views
Problem using select and filter when used in purrr::compose with purrr::partial in R
I'm trying to compose a set of partially applied functions using the purrr package. I'm noticing that I can do this with some functions but not others and I would like to know why (or what am I ...
4
votes
1
answer
125
views
Implementation of Church numeral multiplication in Haskell not working
I'm currently learning about Church encoding and I'm trying to implement the mul (multiply) function.
This is the correct implementation
mul cn cm = \f x -> cn (cm f) x
This (my implementation) ...
0
votes
1
answer
48
views
Writing an R Function That Returns Another Function [closed]
I want to write a function that will output a new function. I've tried the following function, which didn't work.
fxn1 <- function (x) {
if (x > 5) {
fxn2 <- function (y) {
y * 3
...
-1
votes
2
answers
89
views
lambda function uses member variable and produces different results
I dont know why the code runs without errors. From what I learned, in functional programming, same input results in same output and function's internal state cannot be changed from outside. When I ...
1
vote
2
answers
210
views
How can I write a haskell function that applies a function on a list until one of its parameters turns 0?
I have to write the following haskell function:
It receives an Integer (let's call it h) and a list of Integers as
parameters. It should iterate through the list, and increment the
value of each ...
2
votes
2
answers
293
views
How to correctly identify pure functions in functional programming?
Is this function pure or impure?
function greet(name) {
return "Hi I'm " + name;
}
The property of pure function is that it has no side effects and always returns the same output for ...
1
vote
0
answers
153
views
Are numbers also functions in functional programming?
I have been taught in my Bsc course that in functional programming even numbers are functions that return themselves. I've read that lambda calculus consists only of functions and nothing else, so ...
0
votes
4
answers
150
views
Functor over multiple levels
I have this lame attempt:
fmap2 :: (Functor f, Functor g) => (a -> b) -> f (g a) -> f (g b)
fmap2 f f2 = (fmap2 f . fmap f2)
It is supposed to work like this:
fmap2 negate [[1,2], [3]] -- ...
0
votes
2
answers
90
views
Swap values of two IORefs
I need this functionality:
x <- newIORef "x"
y <- newIORef "y"
swapIORefs x y
readIORef x -- Outputs "y"
readIORef y -- Outputs "x"
My best attempt is:
...
0
votes
1
answer
110
views
Deal cards in Haskell
I need to define a function
deal :: [String] -> [String] -> [(String,String)]
It needs to work like this:
deal ["Hercule","Ariadne"] ["Ace","Joker","...
1
vote
1
answer
90
views
Equations for step (function) have different numbers of arguments in a state machine
I have this cake baking state machine in Haskell:
------------------------------------------------------------------------------
-- Ex 3: a state machine for baking a cake. The type Event represents
--...