currying

Currying and compiler design

This is a homework question: Explain the transformations the type of a routine undergoes in partial parameterization. So far I understand currying. But I cannot find any resources on how a function like this is implemented by the compiler in memory. Could I be pointed in the right direction, maybe keywords to search for or link...

How do you curry the 2nd (or 3rd, 4th, ...) parameter in F# or any functional language?

I'm just starting up with F# and see how you can use currying to pre-load the 1st parameter to a function. But how would one do it with the 2nd, 3rd, or whatever other parameter? Would named parameters to make this easier? Are there any other functional languages that have named parameters or some other way to make currying indifferen...

(How) is it possible to bind/rebind a method to work with a delegate of a different signature?

I'm a c++ developer having used signals & slots in c++ which to me seems to be analogous to delegates in c#. I've found myself at a loss in searching for the functionality provided by "bind", and feel I must be missing something. I feel like that something like the following, which is possible in c++ should be possible in c# with delega...

Implementing a def with N parameters as a val of type FunctionN

I can implement a def with a val where the def takes no arguments: trait T { def foo: Int } class C(val foo: Int) extends T Why can this not be extended to implementing a def taking N args to a val which is a FunctionN? I want it possible to implement something like: def expensiveOperation(p: Int => Boolean) : List[Int] With a lazy...

"int -> int -> int" What does this mean in F# ?

I wonder what this means in F#. “a function taking an integer, which returns a function which takes an integer and returns an integer.” But I don't understand this well. Can anyone explain this so clear ? [Update]: > let f1 x y = x+y ;; val f1 : int -> int -> int What this mean ? ...

Confirming Greenspun's 10th Law in C#

I am trying to implement an infrastructure in C# that would allow me to make arbitrary mathematical expressions. For example, I want to be able to take an expression like asin(sqrt(z - sin(x+y)^2)) and turn it into an object that will allow me to evaluate it in terms of x,y, and z, get derivatives, and possibly do some kind of symbolic...

Make this syntax possible: var a = add(2)(3); //5

Make this syntax possible: var a = add(2)(3); //5 I got this question at http://dmitry.baranovskiy.com/post/31797647 Got no clue. Confused.... Know the answer... ...

What is the advantage of Currying in C#? (achieving partial function)

What is the advantage of Currying in C#? What is the advantage of achieving partial function application on a curried function? ...

How to explain method calls?

Hi, let's consider a small method: int MyFunction(string foo, int bar) { ... } and some calls: MyFunction("",0) int x = MyFunction(foo1,bar1) How would you explain this to a non-technical persons? Has anybody a nice metaphor? I tried to explain method calling (or function application) several times, but I failed. Seems I can't ...

Challenge: Neater way of currying or partially applying C#4's string.Join

Background I recently read that .NET 4's System.String class has a new overload of the Join method. This new overload takes a separator, and an IEnumerable<T> which allows arbitrary collections to be joined into a single string without the need to convert to an intermediate string array. Cool! That means I can now do this: var evenNum...

F# currying efficiency?

I have a function that looks as follows: let isInSet setElems normalize p = normalize p |> (Set.ofList setElems).Contains This function can be used to quickly check whether an element is semantically part of some set; for example, to check if a file path belongs to an html file: let getLowerExtension p = (Path.GetExtension p...

Is currying just a way to avoid inheritance?

So my understanding of currying (based on SO questions) is that it lets you partially set parameters of a function and return a "truncated" function as a result. If you have a big hairy function takes 10 parameters and looks like function (location, type, gender, jumpShot%, SSN, vegetarian, salary) { //weird stuff } and you want ...

OCaml: Currying without defined values

I have two functions f and g and I am trying to return f(g(x)) but I do not know the value of x and I am not really sure how to go about this. A more concrete example: if I have functions f = x + 1 and g = x * 2 and I am trying to return f(g(x)) I should get a function equal to (x*2) + 1 ...

Is there a programming language that performs currying when named parameters are omitted?

Many functional programming languages have support for curried parameters. To support currying functions the parameters to the function are essentially a tuple where the last parameter can be omitted making a new function requiring a smaller tuple. I'm thinking of designing a language that always uses records (aka named parameters) for ...

currying functions in python in a loop

So here is some code that simplifies what I've been working on: vars = { 'a':'alice', 'b':'bob', } cnames = ['charlie', 'cindy'] commands = [] for c in cnames: kwargs = dict(vars) kwargs['c'] = c print kwargs commands.append(lambda:a_function(**kwargs)) print commands def a_function(a=None, b=None, c=None): ...

Django - limiting url access to superusers

In my urlconf, i have: url(r'^sssssh/(.*)', staff_only_app.site.root), What I'd like to do is limiting any access to this application to superusers. I tried this: url(r'^sssssh/(.*)', user_passes_test(staff_only_app.site.root, lambda u: u.is_superuser)), But it complains that decorate takes exactly 1 argument, and I gave two. I'...

Is it possible in F# to curry a middle function argument?

Here's code that works fine: let f x y z = x + y + z let g x y = f x y let h x z = z |> f x So I can write expression "h 1", and FSI displays: val it : (int -> int -> int) = <fun:it@110-3> If I call "h 1 2 3", the arguments are applied in the right order. But if the last argument has a different type, things get different: let ff...

How do I get (a, b) => c from a => b => c in Scala?

If I have: val f : A => B => C This is shorthand for: val f : Function1[A, Function1[B, C]] How do I get a function g with the signature: val g : (A, B) => C = error("todo") (i.e.) val g : Function2[A, B, C] //or possibly val g : Function1[(A, B), C] in terms of f? ...

Why is currying and uncurrying not implicit in scala

If I have a function: f : A => B => C I can define an implicit conversion such that this can be used where a function (A, B) => C is expected. This goes in the other direction also. Why are these conversions not implicit (or available implicitly)? I am assuming that bad things could happen for some value of bad things. What value is ...

Currying in YUI3 library

Does YUI3 library have currying functionality ? ...