Conversation
|
http://en.wikipedia.org/wiki/Partial_application. A "partial function" in scala is completely different than a partially applied function. It is as you said a function that applies only to a certain domain. For example In the above code, match is "I believe" shorthand for an anonymous partial function. In this case it would return a match error since the input (the integer 5) would match none of the cases. The term "partial application" I believe is universal and not specific to R. It sounds like this could be a good blog post both for the content, to clear up vocabulary, and address the different approaches used by different languages. Here's a blog post on it in javascript: http://ejohn.org/blog/partial-functions-in-javascript/. Do ya'll have a C# equivalent? I believe Steven said he was familiar with the concept |
|
In C#, you have anonymous functions that support closures, so you can do this. For example: Func<int, int, int> add = (x, y) => x + y; You can also write an extension method on the function type to provide direct currying similar to the javascript article you mentioned, but people don't tend to do this, probably because the parameter ordering constraints of currying means you end up going with the above style a good portion of the time anyway and it doesn't save many characters. |
|
@madelson for R, javascript, and C#, partial application is a particular use of closure. Closure just means that when passing around a function, it will also pass a referencing environment for the "closed" variables. // a simple closure in javascript Can you add some C# examples to the blog post? |
|
Also just to note I realized you can do this the old fashion way in scala too: scala> def add(x: Int, y: Int) = x + y scala> def addFive(x: Int) = { scala> addFive(6) |
There was a problem hiding this comment.
I don't like the wording "a basic example." I think you can more directly speak to the reader by saying something like "let's take a look at a classic example of partial functions." Also, I think it'd be clearer to explain the function we start with and the function we create.
There was a problem hiding this comment.
We should include C# in the list of languages. It's a features that's used often in C# too...even if it's not as functional as scala.
No description provided.