FAQ Database Discussion Community


Passing multiple arguments to curried functions

javascript,function,arguments,closures,currying
I'm currently reading the book, Effective Javascript and have reached the chapter regarding closures. There's an example that illustrates how to pass the argument of a nested function as so: function sandwichMaker(magicIngredient) { function make(filling) { return magicIngredient + " and " + filling; } return make; } var hamAnd...

Currying function cancels polymorphism in OCaml?

types,polymorphism,ocaml,currying
I have a function: let rec loop size elem = if size <= 0 then [] else elem::( loop (size - 1) elem);; And if I type it in the utop I got the type int -> 'a -> 'a list = <fun> which is expected, however if I make...

ML currying and anonymous functions

sml,currying
Could someone please explain to me what is going on in these three bindings? What is the significance of the parens? What is the meaning of g and why does it have to be a g as an argument in the anonymous function? And overall what is actually happening in...

Haskell, is it possible to create a curry function that can curry any number of tuple elements

haskell,currying,partial-application
The current curry function takes a function accepting a tuple of 2 elements and allows the resulting function to be curried or partially applied. let x = curry (\(x, y) -> x + y) x 1 2 -- 3 Is it possible to create a curry function that can deal...

Mapping curry to a list of parameters

functional-programming,scheme,racket,currying
I'm doing some exercises in Racket, and ran into a problem I couldn't seem to query the docs for. I want to generate the following curries of modulo for a list of divisors: (define multlist '[3 5]) (define modfuncs (map (lambda x ;@ make some modulos (curry modulo x)) multlist))...

Apply a list of parameters to a curried function

functional-programming,sml,currying
simple task: all I want is a function to apply a list of parameters to a curried function. Let's say our function is the famous add one: fun add a b = a + b; Now all I want is a function to apply a list (say [1, 5]) to...

swift - partial function application with generics

ios,swift,generics,currying,partial-functions
I'm working with an Observer API (ObserverSet) which have the following function : public func add<T: AnyObject>(object: T, _ f: T -> Parameters -> Void) -> ObserverSetEntry<Parameters> It simply register an object then call the instance method f on the object when notification triggers In one of my manager, I...

Currying in Haskell

haskell,currying
I was manually writing a currying function in Haskell as follows. curry f = \x y -> f(x,y) Then I use this max(x, y) = if x > y then x else y as f, and I wrote max1 = curry max to get the curried function But this is...

Functional Programming - .bind.apply for curry function

javascript,functional-programming,currying
Reading about functional programming - got to currying, example has a simple currying function. I understand everything except the last else block. var curry = function (fn, fnLength) { fnLength = fnLength || fn.length; return function () { var suppliedArgs = Array.prototype.slice.call(arguments); if (suppliedArgs.length >= fn.length) { return fn.apply(this, suppliedArgs);...

F# Changing parameters precedence

f#,pipeline,currying
I'm new to F# and have a question about functions pipeline. Let's say we have a function map which maps list of functions to array of values creating a list of arrays: //val map : ('a -> 'b) list -> 'a [] -> 'b [] list let map funcs vals...

In simplest term, what is currying and why should this approach be favored over traditional programming paradigm?

scala,functional-programming,software-engineering,currying
I am having hard time understanding currying through several sources on web . Isn't there more intuitive example of currying? Also, what are its advantages over traditional programming paradigm ? Is currying possible to achieve on non-functional programmming?...

Reference method from different class as curried function

swift,methods,currying
There are two merge methods in RACSignal: - (RACSignal *)merge:(RACSignal *)signal; + (RACSignal *)merge:(id<NSFastEnumeration>)signals; When I write RACSignal.merge it references static method: class func merge(signals: NSFastEnumeration!) -> RACSignal! How to reference object method? I can't write self.merge, because it is in wrapper class and self is not RACSignal....

How to disambiguate case class creation with multiple parameter lists?

scala,currying
I have a case class that looks about like this: case class A(first: B*)(second: C*) Both first and second are repeated, so I put the in separate parameter lists. However, I expect that second might be empty in a substantial number of cases, so being able to use the class...

javascript curry example in async.js library

javascript,currying,async.js
i was reading the source code for async.js library and with in that i found a function called 'only_once' and then i tried some examples to make it clear how it works, but i can't figure out what is wrong with my examples cause they simply do not behave the...

Determine the arity of a function handle and currying

matlab,functional-programming,currying,arity
Is there any way to determine the arity of a function and/or curry functions in MATLAB? I can't find any documentation on the matter.

Is branching a required feature of currying?

javascript,functional-programming,currying
When writing an implementation of a curry function, is it a requirement to be able to branch? Usage example in Javascript: var foo = function (a, b) { console.log(a, b); }, x = curry(foo), y = x('bar'); // An example of branching x('baz'); // -> 'bar baz' y('qux'); // -...