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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:07:43+00:00 2026-06-02T21:07:43+00:00

I was under the impression that this // short syntax def foo(bar: Bar)(baz: Baz):

  • 0

I was under the impression that this

// short syntax
def foo(bar: Bar)(baz: Baz): Quux

was syntax sugar for this

// long syntax
def foo(bar: Bar): (Baz) => Quux

But I cannot seem to mix the two when it comes to inheritance. The whole tree has to be defined in either the short syntax or the long syntax; never both.

For example:

case class Context
case class Work

trait ContextualWorker {
  def workWithContext(ctxt: Context)(work: Work): Traversable[Work]
}

class ShortConcreteWorker extends ContextualWorker {
  override def workWithContext(ctxt: Context)(work: Work) = Nil
}

class LongConcreteWorker extends ContextualWorker {
  // error on next line: method workWithContext overrides nothing    <-------------
 override def workWithContext(ctxt: Context): (Work) => Traversable[Work] = {
    val setupCode = 1
    { work => Nil }
  }
}

If I change the trait to use the long syntax, then ShortConcreteWorker doesn’t compile.

Is there a reason why these aren’t interchangeable/inheritable? How have you gotten around it?

Right now the most flexible approach appears to be to define the tree in the long syntax, perhaps delegating to an implementation class in ShortConcreteWorker like so:

case class Context
case class Work

trait ContextualWorker {
  def workWithContext(ctxt: Context): (Work) => Traversable[Work]
}

class ShortConcreteWorker extends ContextualWorker {
  override def workWithContext(ctxt: Context) = workWithContextImpl(ctxt)_ 
  private def workWithContextImpl(ctxt: Context)(work: Work) = Nil
}

class LongConcreteWorker extends ContextualWorker {
  override def workWithContext(ctxt: Context): (Work) => Traversable[Work] = {
    val setupCode = 1
    { work => Nil }
  }
}
  • 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-02T21:07:47+00:00Added an answer on June 2, 2026 at 9:07 pm

    The two methods described quite simply have different signatures. The REPL confirms this:

    scala> def foo1(a: Int)(b: Int): Int = a + b
    foo1: (a: Int)(b: Int)Int
    
    scala> def foo2(a: Int): (Int => Int) = (b: Int) => a + b
    foo2: (a: Int)Int => Int
    

    The first is a function that requires two arguments, given in separate argument lists, and returns an Int. The second is a function that takes one argument and returns a function from Int to Int. While these two things are conceptually similar, they are, in fact, different constructs, and Scala treats them as such.

    This is not limited to functions with multiple argument lists. It works the same way here:

    scala> def foo3(a: Int): Int = a + 1
    foo3: (a: Int)Int
    
    scala> def foo4: (Int => Int) = (a: Int) => a + 1
    foo4: Int => Int
    

    Note that there are different ramifications for usage as well. With foo2, because it only accepts one argument, we can call it with just one argument. However, foo1 requires two arguments, an so we cannot simply call it with one. You can however use the _ syntax to convert it into a callable function.

    foo2(2)    // Int => Int = <function1>
    foo1(2)    // error: missing arguments for method foo1
    foo1(2) _  // Int => Int = <function1>
    

    So to answer your question directly: The reason they are not interchangeable is because they are not the same. If they were the same, we would be able to call them the same way. If you could change the signature upon extension, how would Scala know which calling syntax to allow? The way to “get around” this is to simply make the signatures consistent.

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

Sidebar

Related Questions

I was under the impression that this was formed correctly, but here it is
I was under the impression that this code #include <windows.h> #include <stdio.h> int WINAPI
I was under the impression all this time that .on() worked like .live() with
I was under the impression, after reading this article that it is better to
I was under the impression that jQuery is JavaScript Framework, but when am searching
I may have a misunderstanding but I was under the impression that having a
I just read this: http://haacked.com/archive/2008/11/20/anatomy-of-a-subtle-json-vulnerability.aspx I was under the impression that overwriting Object or
I was under the impression that using the Resolve method returned a new instance
I was under the impression that I could put any old executable program in
I was under the impression that when you double click a file (or choose

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.