Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Partial Application #26

Open
alexispurslane opened this issue Dec 15, 2014 · 13 comments
Open

Partial Application #26

alexispurslane opened this issue Dec 15, 2014 · 13 comments

Comments

@alexispurslane
Copy link

I think that currying would be highly convenient in a stream-based programming language! Check this out:

seq(100) | (% 5) | STDOUT

or

seq(100) | (_ % 5) | STDOUT
@alexispurslane
Copy link
Author

So that when you call a function with missing arguments, it returns another function that takes the rest of those arguments. That would be great for streem because then we can use functions lake transformations and filters, passing in one argument, and letting the stream fill in the rest! Otherwise, we would have to do this:

seq(100) | {|x| 
  if x % 5 {
    x
  }
} | STDOUT

@nickserv
Copy link
Contributor

That seems pretty awesome, I agree that currying would be pretty useful in this situation.

However, how would this affect calling syntax? For example, what if there are optional parameters? Also, if there is not a lot of type checking going on, this could confuse people if they curry by accident.

@alexispurslane
Copy link
Author

I was thinking using an underscore for a missing parameter. That way function calls, optionals, and so-on wouldn't be confused:

seq(100) | (_ % 5) | STDOUT

@pvwoods
Copy link

pvwoods commented Dec 16, 2014

depending on data type support within the language, how would tuple/set access work?

(_._1 % 5) or (_[0] % 5) come to mind... not sure what would be the cleanest option.

@shouya
Copy link

shouya commented Dec 16, 2014

+1 for the currying. Also take a look at this pretty awesome gem https://cirw.in/blog/ampex, which enables you to do more complex shorthand operations like &X ** 2 / 2 instead of -> {|x| x ** 2 / 2}.

@shouya
Copy link

shouya commented Dec 16, 2014

@ChristopherDumas That's kinda like what you can do in Scala's anonymous functions... I don't know what is this syntax's name.

@nickserv
Copy link
Contributor

Would _ be used for a curried parameter or an optional parameter?

@alexispurslane
Copy link
Author

_ would be a curried parameter. Optional parameters just wouldn't be supplied, just missing. (......of course, we could do it the other way around........)

@shuichiro-makigaki
Copy link
Contributor

Currying is good idea, and I'd like to add +1. But, if Streem supports bit operation, I'm afraid:

seq(100) | (_ | 3 | 5) | STDOUT

hmm, too many bars... The proposed syntax looks good to me, but users shouldn't use complex operations in currying!

@alexispurslane
Copy link
Author

Agreed, but that is more of a stylistic issue.

@dajoh
Copy link

dajoh commented Dec 20, 2014

Shouldn't (_ % 5) or (% 5) be a function from Int -> Int, and not Int -> Maybe Int as this implies:

{|x| 
  if x % 5 {
    x
  }
}

That function also doesn't have the same "output integer" (x vs x mod 5).

@dajoh
Copy link

dajoh commented Dec 20, 2014

Also, this isn't called currying, this is called partial application. I suggest you change your wording.

@alexispurslane
Copy link
Author

Got it. Changing issue name....

@alexispurslane alexispurslane changed the title Currying Partial Application Dec 20, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants