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

SML currying ( functional prog)?

I asked this question a few days ago but now I have more understanding on the subject. But I still get problem that operator and operand dont agree: Using ListPair.foldr I need to create a function zipWith that combines pairwise two lists. The type…
user2012107
  • 9
  • 1
  • 3
-2
votes
1 answer

How would i make a function for it as well which will keep track of the empty values of second argument

multiply(10)()()()(12) This a function call and we have to make a function to multiply 2 numbers
-2
votes
2 answers

Recursively calling a curried function in Javascript

As a toy example lets say we have this function and its usage: const map = (f = n => n + 1) => (lst = [1,2,3]) => { if(lst.length === 0) return []; else return [f(...lst.splice(0,1)), ...map(f)(lst)]; } const inc = n => n +…
SultanLegend
  • 535
  • 3
  • 11
-2
votes
1 answer

How to deal with List of currying function in Scala

In the following Scala code I have a sequence of currying functions with different signatures. I want to iterate through them and invoke. def intCheck(b: Int)(a: Int) = a == b def stringCheck(b: String)(a: String) = a == b def doubleCheck(b:…
Anil Kurian
  • 223
  • 2
  • 3
-2
votes
2 answers

Can someone help me understand this piece of code in Javascript?

var curryIt = function(uncurried) { var parameters = Array.prototype.slice.call(arguments, 1); return function() { return uncurried.apply(this, parameters.concat( Array.prototype.slice.call(arguments, 0) )); }; }; var greeter =…
Ajayv
  • 374
  • 2
  • 13
-3
votes
1 answer

Is this a curried function?

I am studying for JS coding interviews and just wanted a simple example of JS currying. Does this example pass as currying? function curry(a){ return function(b){ return function(c){ console.log(a+b+c) } } } …
-3
votes
1 answer

What is going on in this code ? I do not understand how this works could someone please step me through this

Can someone please explained the steps that are happening in this code particularly the marked part. Is it recursive how does it slot together..? const func = x => k => func (k (x)) // ^^^^^^^^^^^^ const add = x => y => …
-3
votes
1 answer

When is it appropriate to curry a function, and when is it not? Why?

How could I write a javascript function knowing whether it needs to be curried?
fifn2
  • 382
  • 1
  • 6
  • 15
-3
votes
2 answers

Currying - How is returned function called with a second argument in JavaScript?

How does the second argument get called in liftf(add)(1)? function add (first, second) { return first + second; } function liftf (binary) { return function (first) { return function (second) { return binary(first,…
K3ARN3Y
  • 11
  • 1
-3
votes
1 answer

Why does using my function as a parameter for another function cause an error? Haskell

I have two functions: f1 :: Bool -> Int f1 x | x == True = 5 | x == False = 10 f2 :: Int -> Int f2 x = x * 2 Since the output of f1 is the correct input for f2, how come f2 f1 True causes an error? I didnt know what to tag so the…
Arthur
  • 347
  • 1
  • 4
  • 14
-5
votes
4 answers

JavaScript: Multiple arguments

Give an example how "currying" might be used in JavaScript: const component = (argument1) => (argument2) => { // Do something }
Michael Niño
  • 437
  • 5
  • 19
-7
votes
1 answer

Sum of list arguments using currying in scala

I am trying to get the sum of arguments using currying in Scala. This is a very basic question so please don't go hard on it. If you can answer the question then please otherwise let it be: object MultiSum extends App { var res=0 …
Abhinav
  • 658
  • 1
  • 9
  • 27
1 2 3
70
71