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 6172333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:22:27+00:00 2026-05-23T23:22:27+00:00

In Scala one can write (curried?) functions like this def curriedFunc(arg1: Int) (arg2: String)

  • 0

In Scala one can write (curried?) functions like this

def curriedFunc(arg1: Int) (arg2: String) = { ... }

What is the difference between the above curriedFunc function definition with two parameters lists and functions with multiple parameters in a single parameter list:

def curriedFunc(arg1: Int, arg2: String) = { ... }

From a mathematical point of view this is (curriedFunc(x))(y) and curriedFunc(x,y) but I can write def sum(x) (y) = x + y and the same will be def sum2(x, y) = x + y

I know only one difference – this is partially applied functions. But both ways are equivalent for me.

Are there any other differences?

  • 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-05-23T23:22:28+00:00Added an answer on May 23, 2026 at 11:22 pm

    Strictly speaking, this is not a curried function, but a method with multiple argument lists, although admittedly it looks like a function.

    As you said, the multiple arguments lists allow the method to be used in the place of a partially applied function. (Sorry for the generally silly examples I use)

    object NonCurr {
      def tabulate[A](n: Int, fun: Int => A) = IndexedSeq.tabulate(n)(fun)
    }
    
    NonCurr.tabulate[Double](10, _)            // not possible
    val x = IndexedSeq.tabulate[Double](10) _  // possible. x is Function1 now
    x(math.exp(_))                             // complete the application
    

    Another benefit is that you can use curly braces instead of parenthesis which looks nice if the second argument list consists of a single function, or thunk. E.g.

    NonCurr.tabulate(10, { i => val j = util.Random.nextInt(i + 1); i - i % 2 })
    

    versus

    IndexedSeq.tabulate(10) { i =>
      val j = util.Random.nextInt(i + 1)
      i - i % 2
    }
    

    Or for the thunk:

    IndexedSeq.fill(10) {
      println("debug: operating the random number generator")
      util.Random.nextInt(99)
    }
    

    Another advantage is, you can refer to arguments of a previous argument list for defining default argument values (although you could also say it’s a disadvantage that you cannot do that in single list 🙂

    // again I'm not very creative with the example, so forgive me
    def doSomething(f: java.io.File)(modDate: Long = f.lastModified) = ???
    

    Finally, there are three other application in an answer to related post Why does Scala provide both multiple parameters lists and multiple parameters per list? . I will just copy them here, but the credit goes to Knut Arne Vedaa, Kevin Wright, and extempore.

    First: you can have multiple var args:

    def foo(as: Int*)(bs: Int*)(cs: Int*) = as.sum * bs.sum * cs.sum
    

    …which would not be possible in a single argument list.

    Second, it aids the type inference:

    def foo[T](a: T, b: T)(op: (T,T) => T) = op(a, b)
    foo(1, 2){_ + _}   // compiler can infer the type of the op function
    
    def foo2[T](a: T, b: T, op: (T,T) => T) = op(a, b)
    foo2(1, 2, _ + _)  // compiler too stupid, unfortunately
    

    And last, this is the only way you can have implicit and non implicit args, as implicit is a modifier for a whole argument list:

    def gaga [A](x: A)(implicit mf: Manifest[A]) = ???   // ok
    def gaga2[A](x: A, implicit mf: Manifest[A]) = ???   // not possible
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

One can write scripts in Scala. So you can put this into Hello.scala #!/bin/sh
Using Scala's command line REPL: def foo(x: Int): Unit = {} def foo(x: String):
In scala I can write: val pf: PartialFunction[String, Unit] = {case s => println(s)}
While playing around with regexps in Scala I wrote something like this: scala> val
In Java you can write Boolean.valueOf(myString) . However in Scala, java.lang.Boolean is hidden by
Newbie here...can I write one program which incorporates .NET LINQ and also various Java
Following on from this question , can someone explain the following in Scala: class
How might one implement C# yield return using Scala continuations? I'd like to be
In Chapter 9 of Programming In Scala, there is an example method like this:
I'd like to write a type alias to shorten, nice and encapsulated Scala code.

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.