Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8596097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:35:46+00:00 2026-06-12T00:35:46+00:00

I was just watching lecture 2.2 Higher order functions (for the Functional programming principles

  • 0

I was just watching lecture 2.2 Higher order functions (for the Functional programming principles in Scala). There, a sum function is defined like this:

def sum(f: Int => Int, a: Int, b: Int) { ... }

Later on, the same function is defined like this:

def sum(f: Int => Int)(a: Int, b: Int) { ... }

They seem to be equivalent, but no explanation is given why to choose on over the over.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:35:47+00:00Added an answer on June 12, 2026 at 12:35 am

    The second definition declares a method with two argument lists. Ignoring implicits, then this is usually used to enable curried function applications. The basic idea is that you can bind some parameters of a function, which yields another function with fewer arguments left, namely the ones that are not yet bound. Here is a simple text book example:

    def add(xs: List[Int])(y: Int) =
      xs.map(_ + y)
    
    // Bind first argument and store resulting function in f
    val f = add(List(2,3,5,7,11))_
    
    println(f(0))  // List(2, 3, 5, 7, 11)
    println(f(10)) // List(12, 13, 15, 17, 21)
    
    // Bind first argument and store resulting function in g
    val g = add(List(0,1,0,1,0,1))_
    
    println(g(1))  // List(1, 2, 1, 2, 1, 2)
    println(g(-1)) // List(-1, 0, -1, 0, -1, 0)
    
    // Regular invocation
    println(add(List(1,2,3))(4)) // List(5, 6, 7)
    

    You’ll find plenty of articles about currying online, for example, how to use currying in Scala, or that there are multiple ways to curry in Scala.

    Regarding why to choose one over the over: In Haskell you would basically always choose the curried version over the uncurried one since the latter gives you the advantage of being able to partially bind parameters, and since there is no “syntax penalty” or runtime penalty for using curried versions. Since this is not true for Scala (as you can observe from the above code snippet when it comes to syntax), you might probably want to prefer the uncurried style except if you know that the most likely use cases of your methods/functions would benefit from currying.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just been watching the Stanford iPhone lecture online from Jan 2010 and
I was just watching a few videos on Channel9. I found things like lambdas
I've just been watching the QCON presentation about Disruptor. It looks like (and it
I'm watching this lecture: http://www.youtube.com/watch?v=Kq4FpMe6cRs // the speaker states that 'bar' is just some
I was just watching Scott Hanselman's presentation on ASP.NET MVC in San Francisco. After
Just learning the world of jquery, and all my googling gives examples like this:
Just a knowledge question which I would like to ask: For example, I have
just wondering if there is a way to reduce the amount of code needed
I just started watching the 2010-11 WWDC iPhone videos and so far love them,
I have just finished watching the following videos in an attempt to understand JDO

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.