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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:26:11+00:00 2026-05-24T23:26:11+00:00

See this example: def hello(a:String, b:String) = println(a + : + b) val m1

  • 0

See this example:

def hello(a:String, b:String) = println(a + ":" + b)
val m1 = hello("aaa", _ )
m1("bbb")

It can’t be compiled, that I need to add the type to the partial method:

val m1 = hello("aaa", _: String)

Why scala doesn’t know the 2nd parameter of method hello is String?

  • 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-24T23:26:11+00:00Added an answer on May 24, 2026 at 11:26 pm

    Scala’s type inference is flow based. Methods and functions need explicit parameter types, which are used to infer other types. The parameter types cannot be inferred from method or function body. Sometimes, however, the parameter types are known from external context, and then don’t have to be labeled. Two examples,

    val f: String => Unit = hello("aaa", _)
    val s = Seq(1,2).map(_+1) // Seq[Int].map expects a function of Int argument type
    

    Below is a quote from Martin Odersky about the limitations of Scala’s type inference compared to, say, ML and Haskell. Challenges include Scala’s overloading, record selection, and subtyping, as well as the need to keep things simple,

    The reason Scala does not have Hindley/Milner type inference is that
    it is very difficult to combine with features such as overloading (the
    ad-hoc variant, not type classes), record selection, and subtyping.
    I’m not saying impossible — there exist a number of extensions that
    incorporate these features; in fact I have been guitly of some of them
    myself. I’m just saying it’s very difficult to make this work well in
    practice, where one needs to have small type expressions, and good
    error messages. It’s not a shut case either — many researchers are
    working on pushing the boundaries here (look for instance at Remy’s
    MLF). But right now it is a tradeoff of better type inferencing vs
    better support for these features. You can make the tradeoff both
    ways. The fact that we wanted to integrate with Java tipped the scales
    in favor of subtyping and away from Hindley/Milner.

    Source: comment under post Universal Type Inference is a Bad Thing.

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

Sidebar

Related Questions

Consider this example: zh_Hant_HK format = yy'年'M'月'd'日' ah:mm Not sure if you can see
I see a lot of example code for C# classes that does this: public
See, for example, §13.3.3 and §13.3.4 . It doesn't seem to me that this
Consider this example: class MyClass: def func(self, name): self.name = name I know that
see the example: from visual import * def hello(): newyear=2010 sphere() return newyear my
See this example! int main( int argc, char ** argv ) { int *ptr
For more information see this Example use strict; use warnings; use CGI::Simple; use DBI;
My current solution will suck sometimes EDIT For those who don't understand,see this example:
Looking for a proven to work algorithm for production. Did see this example but
I would like to see how this example of existing code would be able

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.