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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T11:52:12+00:00 2026-06-14T11:52:12+00:00

There’s an example in Scala in Depth where the author is explaining how scala

  • 0

There’s an example in “Scala in Depth” where the author is explaining how scala can do some level of inference on the arguments passed into the methods. As an example the following is shown:

def myMethod(functionLiteral: A => B):Unit
myMethod({ arg:A => new B})
myMethod({ arg => new B})

Just to figure out what the author is talking about, I do the following in the REPL:

def myMethod(functionLiteral: Boolean => Boolean):Unit = {}
myMethod({a:Boolean => true})
myMethod({a => true})

The only revelatory thing that happens here is that the compiler doesn’t throw an error.

Is the author trying to say that the function argument a is inferred to be a Boolean by the compiler?

  • 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-14T11:52:13+00:00Added an answer on June 14, 2026 at 11:52 am

    Yes the author is saying that dont need to specify that a is a Boolean in myMethod({a => true}) because the type is Boolean => Boolean

    == Original answer which makes the first bit compile but misses the point a bit ==

    It needed to Be typed with [A,B].

    def myMethod[A,B](functionLiteral: A => B): Unit = {}
    myMethod((arg:String) => arg.length)
    myMethod((arg:Int) => (1 to arg).map(_ *2))
    

    I modified it to return the function so you can see the types in the repl.

    scala> def myMethod[A,B](functionLiteral: A => B): A => B = functionLiteral
    myMethod: [A, B](functionLiteral: (A) => B)(A) => B
    
    scala> myMethod((arg:String) => arg.length)
    res11: (String) => Int = <function1>
    
    scala> res11("hello world!")
    res12: Int = 12
    
    scala> myMethod((arg:Int) => (1 to arg).map(_ *2))
    res13: (Int) => scala.collection.immutable.IndexedSeq[Int] = <function1>
    
    scala> res13(4)
    res14: scala.collection.immutable.IndexedSeq[Int] = Vector(2, 4, 6, 8)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are some stdlib functions that throw errors on invalid input. For example: Prelude>
There can only be one IDENTITY column per table Why is it so? Take
There are a lot of example implementations of daemons on the net. Most that
There's no Sort() function for IList . Can someoene help me with this? I
There are some Magento Connect extensions that I find myself installing every time I
There is a QListWidget containing keywords for search and a QTextEdit containing some text.
There is some contradiction in the api documentation: on one location: https://developer.foursquare.com/docs/responses/user on another
There was some progress made to the earlier problem. Now there is a new
There are many string matching algorithms can be used to find a pattern (string)
There are some keywords in text and start/end position of their occurrences. Keywords may

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.