Skip to main content

Questions tagged [higher-order-functions]

Higher-order functions are functions which either take functions as arguments or return them as output (or both). They are a cornerstone of functional programming.

higher-order-functions
0 votes
1 answer
37 views

Type for heterogeneous *args

In typed Python, how do you type a *args list that you're expecting to pass to another argument that is a higher kinded function? For example, this function takes a function and its first argument and ...
Mike Samuel's user avatar
4 votes
3 answers
143 views

How does <$ = (fmap . const) in Functor even work in Haskell?

I know that the dot (.) operator takes two functions which both take an argument respectively, and the third argument for the second argument. Its type is (.) :: (b -> c) -> (a -> b) -> a -...
Akari's user avatar
  • 145
0 votes
4 answers
102 views

Create a list accumulating the results of calling a function repeatedly on an input value

Is there a library function that creates recursive lists in the following sense, recursive_list(f, x0, n) = [x0, f(x0), f(f(x0)), f(f(f(x0))), ...] with n elements in the returned list? If not, how ...
Evan Aad's user avatar
  • 5,965
-5 votes
2 answers
80 views

Appropriate defining equations for Haskell functions

The task is to give appropriate defining equations for the following functions: curry :: ((a, b) → c) → a → b → c uncurry :: (a → b → c) → (a, b) → c curry takes one function and two types (a,b) ...
holypropa's user avatar
0 votes
3 answers
57 views

I don't understand this example for a callback function, in which we callback a function which hasn't actually been declared

In the below example from Codecademy, I don't really understand how the console can process the 'artist' parameter in a higher-order function, considering that we've only declared 'artists' up to this ...
kingsliceman's user avatar
1 vote
2 answers
76 views

How does this nested lambda function work?

How do we get the output of 120? I don't quite understand what is x(y) in the function. Which arguments are passed into which function? def combinator(y): return (lambda x: lambda y: x(y))(lambda x:...
Jeff Beh's user avatar
0 votes
2 answers
48 views

why is my higher order function returning true and false?

I have to create my own higher order filter() function to filter an array of 10 words that only returns word that have 6 or more letters but my function is only returning true and false and not ...
NewQode10's user avatar
0 votes
0 answers
56 views

Understanding use of closure in callback in javascript [duplicate]

I am trying to understand how closure is used in callback function in javascript.Can anybody explain me in detail ? function fetchData(url, callback) { fetch(url) .then((response) => ...
sangram's user avatar
  • 395
1 vote
1 answer
161 views

How do I pass a generic function as an argument to another function in golang?

How do i modify transformNumbers function so that it works with generic function doubleG and tripleG type trandformFn func(int) int func transformNumbers(numbers *[]int, transform trandformFn) []int {...
Ayush Nigam's user avatar
0 votes
2 answers
123 views

How does combining higher-order functions work in JavaScript?

The first book I have bought on JavaScript was unfortunately not for beginners. The book is "the joy of JavaScript" from Luis Atencio. I am still trying to understand some concept in this ...
djbone's user avatar
  • 35
1 vote
1 answer
130 views

SiCP Exercise 1.45

Update: I changed the argument 1 in nth-root to 1.0, and then it works. Why are they different? Here's my original question. I have (define tolerance 0.00001) (define (fixed-point f first-guess) (...
run an's user avatar
  • 23
1 vote
1 answer
168 views

Custom JVP and VJP for higher order functions in JAX

I find custom automatic differentiation capabilities (JVP, VJP) very useful in JAX, but am having a hard time applying it to higher order functions. A minimal example of this sort is as follows: given ...
Jingyang Wang's user avatar
0 votes
0 answers
54 views

How can I get strongly-typed higher order functions in Typescript?

See the below code block: interface TestHiveInput { input: string; } interface TestHiveOutput { output: string; } type ListenFunction = (value: any) => void; type Hive<T, K> = (...
msbb's user avatar
  • 53
1 vote
2 answers
174 views

Linear combination of functions in C++

Let's say we have the following: // some functions double f1( double x ); double f2( double x ); double f3( double x ); // coefficients double c1, c2, c3; // input variable double x; We need to ...
soad's user avatar
  • 61
0 votes
0 answers
32 views

Need help understanding whether internal state of viewModel is automatically updated along with ProtoDataStore

Working on an android app (personal project) with Kotlin and Jetpack. Using Proto datastore to store application settings/configurations. Using Hilt for D.I. My code was just working fine with ...
TheSelfTaughtNoob's user avatar

15 30 50 per page
1
2 3 4 5
108