Questions tagged [currying]

Currying is the process of transforming a function of multiple arguments into a function of one argument that returns another function, which takes one fewer argument than the original one. Languages such as Haskell use this as the default argument application mechanism, as it makes certain programming techniques, such as partial application, much easier.

Currying is the process of transforming a function of multiple arguments into a function of one argument that returns another function, which takes one fewer argument than the original one. Languages such as use this as the default argument application mechanism, as it makes certain programming techniques, such as , much easier.

The technique originates in , and was independently discovered by Frege, Schönfinkel and Curry in the early 20th century.

Example of manual currying ()

Uncurried form

/* definition */
let add = (a, b) => a + b;

/* full application */
let x = add(2, 4);

/* partial application */
let add2 = add.bind(null, 2);
let y = add2(4);

Curried form

/* definition */
let add = a => b => a + b;

/* full application */
let x = add(2)(4);

/* partial application */
let add2 = add(2);
let y = add2(4);

Curried programming languages

1062 questions
-1
votes
1 answer

JS: Explaining the usage of currying vs multi-args

If I chose to curry this function: function mult(a,b,c) { return a * b * c; } into : function mult(a) { return function(b) { return function(c) { return a * b * c; } } } What is the benefit? Is it that if I…
hortenzz1
  • 33
  • 4
-1
votes
1 answer

JavaScript currying: return a function defined outside the current function

I'm studying currying functions in JS and I got stuck with this problem. My goal is to order an array of objects by a non-arbitrary property. let people = [ { name: 'Bob', age: 27 }, { name: 'Al', age: 47 } ]; var compare = function(a, b)…
Couper
  • 414
  • 5
  • 13
-1
votes
1 answer

Function composition using Go syntax

Below is the problem: Define a function make_fn_repeater which takes in a one-argument function f and an integer x. It should return another function which takes in one argument, another integer. This function returns the result of applying f to x…
overexchange
  • 15,768
  • 30
  • 152
  • 347
-1
votes
2 answers

How to define a list of non-constant functions in a loop with lambda functions?

Let's say that I want to create a list of functions funclist, such that the fonctions of this list behave that way: funclist[0](x) = 0 funclist[1](x) = x funclist[2](x) = 2*x funclist[3](x) = 3*x Assuming that the list is too long (say of size 100)…
Guillaume
  • 257
  • 1
  • 8
-1
votes
1 answer

Is it valid to include declarations and ternaries while currying in Javascript?

I'm wondering if it's considered valid, from a functional programming perspective, to include declarations and ternaries while currying in Javascript, like so: const one = (a) => { return (b) => { return (c) => { const new = c + b; …
-1
votes
1 answer

Javascript high order functions - How do pass a variable from to function to it's parent function

I'm trying to solve this algorithm. I think I'm very close. I need the seven function to pass the a variable to the timesFive function. OR is there a way I can pass the * 5 operation from timesFive to seven in order to get the desired result? I'm…
-1
votes
1 answer

implement equivalent arrow function and normal function with rest parameters (variable arguments)

I want to implement an arrow function which is equivalent to another normal function works like the following example: f(h)(a1)(a2)...(an) works like h(a1, a2, ..., an). I think I have to implement it with the following psuedocode, but I don't…
Somehow
  • 41
  • 7
-1
votes
1 answer

How to curry list of function in scheme?

so compose function curries multiple functions together suppose ((compose sin cos tan asin) 0) so expecting output to be as (sin (cos (tan (asin x)))) (define (compose f . g) (lambda(x) (if(eq? (cdr g) '()) (f ((car g) x)) (f…
ganesh
  • 171
  • 1
  • 2
  • 13
-1
votes
1 answer

When would a function's actual .length be insufficient for _.curry()

I was running into a wonky situation where a function using _.curry on a was invoking the function immediately. After reading the lodash docs, we figured out we needed to declare arity, thanks to the very well written docs: The arity of func may…
bazeblackwood
  • 1,127
  • 6
  • 16
-1
votes
2 answers

In Haskell, how would I return a curried function that has a recursive definition?

I am trying to achieve the following (defined in Javascript) in Haskell: JS: const fold = (c, h) => { const f = (n) => { return n === 0 ? c : h (f(n-1)) } return f } fold(1, (x)=>x*10)(3) Repl Link:…
coder_bro
  • 10,503
  • 13
  • 56
  • 88
-1
votes
1 answer

Whats the advantages and the disadvantages of curried functions

I just know that it's it easy partial application and it's that it can (and does, for Haskell) simplify the syntax?
joshua
  • 947
  • 2
  • 8
  • 14
-1
votes
2 answers

OCaml currying example

I am writing an OCaml function that accepts a function type, such as (fun _ -> true) and a list. This is what I currently have: let drop_until_boolean (x: 'a -> bool) lst = match lst with | x -> true Currently that written statement does…
-1
votes
1 answer

Why curried function in OCaml, but not in Java

I noticed that in OCaml we are allowed to use currying function like let add = fun y -> (fun x -> x + y) ;; But my professor stated that this kind of format is not allowed in Java. For example, given a method foo1, it is possible to have…
Yufan Fei
  • 59
  • 6
-1
votes
2 answers

What is the use of currying in javascript?

Theortically I know what currying is. Can anyone tell me the practical use of currying in javascript?
Rohit Goyal
  • 212
  • 1
  • 2
  • 8
-1
votes
1 answer

(Haskell) Parse error in pattern after Currying

I am getting a parse error after I changed this: h :: ([Int],Int,[Int])->[[Int]] h ([],k,x) =[[]] h(y:[],k,x) = [x++k:[y]] h(y:xs,k,x)= [x++k:y:xs]++h(xs,k,x++[y]) to this: at line 3 h :: [Int]->Int->[Int]->[[Int]] h [] k x =[[]] h (y:[]) k x…
SambaBoy
  • 3
  • 1
1 2 3
70
71