• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How do i 'curry' in scala

 
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

OK, first of all, I am admitting that I am not experienced with Scala at all, After buying Venkat's book, which I must admit is really hot! I tried a few things in first 4-5 chapters I guess (this is more of coding and less of reading ... ), anyways, I was able to intuitively (beauty of Scala?) do anonymous functions and invoke them, however i can't figure out how do i define a lambda expression so as to speak, or something which takes function as an argument or returns a function or both... the whole notation (I decided to not read by skipping chapters, (there's a functions chapter in the book ...), but couldn't resist doing it myself first =) .. I wrote this but it didn't compile:



Any suggestions?

Trilochan
 
Trilochan Bharadwaj
Ranch Hand
Posts: 100
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, I searched this forum and got an excellent link:
Functions in Scala
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm not sure what you were going for, but as you saw in that blog posting, to define a method that takes a function argument you use either one of the following equivalent methods.



You can call it with either a named method, or by an anonymous function:
 
Ranch Hand
Posts: 376
Scala Monad
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looks like currying is something different than what you where trying to accomplish.
Currying is simply the transformation of a function with multiple parameters into another function with only one parameter that returns a function of the remaining parameters.
In Scala, if you want to write curried functions, you just separate the parameters with parenthesis.
If the normal(uncurried) function is:

then, the curried version is:

A while ago, I did a blog entry on currying in Scala vs Haskell
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic