Once again, some misinformation. Scala also provides a "curry" method on
functions. This converts the function into a completely curried function
(i.e. [ (x,y,z) => A] becomes x => y => z => A
scala> def foo = (what : String, who : String) => println(who + " loves the
" + what)
foo: (String, String) => Unit
scala> foo("Groovy", "Dick")
Dick loves the Groovy
scala> def bar = foo.curry("Scala")
bar: (String) => Unit
scala> bar("Robert")
Robert loves the Scala
On Fri, May 15, 2009 at 11:32 PM, Andres Almiray <[email protected]> wrote:
>
> Hmmm here some Groovy code:
>
> def foo = { what, who -> println "$who loves the $what" }
> foo( "Groovy", "Dick" ) // prints "Dick loves the Groovy"
> def bar = foo.curry("Scala")
> bar( "Robert" ) // prints "Robert loves the Scala"
>
> Did I plan for foo to be curried in the first place? no I did not,
> that is the point Robert made in his post regarding currying and
> syntax.
>
> On May 15, 7:45 pm, Michael Neale <[email protected]> wrote:
> > Currying is when you write a function in such a way as it can be
> > partially applied, so in languages like haskell, it "curries" all
> > functions by default then (and I guess for other ML derivatives??).
> >
> > On May 16, 9:40 am, Andres Almiray <[email protected]> wrote:
> >
> > > Yes, Scala supports a terser syntax for currying as you have shown,
> > > but you're missing Robert's point: OCaml (as well as other languages
> > > like Groovy) support currying any function, regardless of how it was
> > > defined. In the case of the Scala option you depicted
> > > _you_have_to_know_ in advance you'd like to curry that function.
> >
> > > So, while other languages support curry "on the go" not so in Scala,
> > > you have to take a moment to think what you want to accomplish, which
> > > is *not* a bad idea to start with.
> >
> > > On May 15, 2:45 am, Viktor Klang <[email protected]> wrote:
> >
> > > > Sorry man, seems that you've basically misinformed.
> >
> > > > Define a top-level function:
> >
> > > > object f extends ((Int) => Int) { def apply(x:Int) = x + 1 }
> >
> > > > Currying:
> >
> > > > def f(x:Int)(y:Int) = x + y
> >
> > > > On Fri, May 15, 2009 at 2:35 AM, Robert Fischer <
> >
> > > > [email protected]> wrote:
> >
> > > > > If Dick is going to keep going on about how functional and
> mathematical
> > > > > Scala is, and how that's so
> > > > > great, maybe he should check out OCaml/F#?
> >
> > > > > I've just posted to my blog about how Scala is *not* a functional
> language.
> > > > > Which is not to say
> > > > > it's a bad language -- it's just not a functional language.
> >
> > > > >http://enfranchisedmind.com/blog/posts/scala-not-functional/
> >
> > > > > ~~ Robert Fischer.
> > > > > Grails Training http://GroovyMag.com/training
> > > > > Smokejumper Consultinghttp://SmokejumperIT.com
> > > > > Enfranchised Mind Bloghttp://EnfranchisedMind.com/blog
> >
> > > > > Check out my book, "Grails Persistence with GORM and GSQL"!
> > > > >http://www.smokejumperit.com/redirect.html
> >
> > > > --
> > > > Viktor Klang
> > > > Rockstar Developer
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "The
Java Posse" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/javaposse?hl=en
-~----------~----~----~----~------~----~------~--~---