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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:17:34+00:00 2026-05-23T01:17:34+00:00

Forgive me if this has already been asked elsewhere. I have a Scala syntax

  • 0

Forgive me if this has already been asked elsewhere. I have a Scala syntax question involving function-values and implicit parameters.

I’m comfortable using implicits with Scala’s currying feature. For instance if I had a sum function and wanted to make the second argument an implicit:

scala> def sum(a: Int)(implicit b: Int) = a + b
sum: (a: Int)(implicit b: Int)Int

Is there a way to do this using the function-value syntax? Ignoring the implicit for a moment, I typically write curried function-values like this:

scala> val sum2 = (a: Int) => (b: Int) => a + b
sum: (Int) => (Int) => Int = <function1>

However, the function signature in the second approach is much different (the currying is being expressed explicitly). Just adding the implicit keyword to b doesn’t make much sense and the compiler complains as well:

scala> val sum2 = (a: Int) => (implicit b: Int) => a + b
<console>:1: error: '=>' expected but ')' found.
       val sum2 = (a: Int) => (implicit b: Int) => a + b
                                              ^

Furthermore partially-applying sum from the very first approach to get a function-value causes problems as well:

scala> val sumFunction = sum _
<console>:14: error: could not find implicit value for parameter b: Int
       val sumFunction = sum _
                         ^

This leads me to believe that functions that have implicit parameters must have said parameters determined when the function-value is created, not when the function-value is applied later on. Is this really the case? Can you ever use an implicit parameter with a function-value?

Thanks for the help!

  • 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-23T01:17:35+00:00Added an answer on May 23, 2026 at 1:17 am
    scala>  val sum2 = (a: Int) => {implicit b: Int => a + b}
    sum2: (Int) => (Int) => Int = <function1>
    

    This will just make b an implicit value for the scope of the function body, so you can call methods that expect an implicit Int.

    I don’t think you can have implicit arguments for functions since then it is unclear what the function is. Is it Int => Int or () => Int?

    The closest I found is:

    scala> case class Foo(implicit b: Int) extends (Int => Int) {def apply(a: Int) = a + b}
    defined class Foo
    
    scala> implicit val b = 3
    b: Int = 3
    
    scala> Foo()
    res22: Foo = <function1>
    
    scala> res22(2)
    res23: Int = 5
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Forgive me if this question has already been asked and answered. Given a class
Forgive me if this has already been asked, I couldn't find it. I have
Forgive me if this has already been asked (and feel free to provide a
Forgive me if this has already been asked, but I'm new to C# and
Forgive me if this has been asked elsewhere. I was not able to find
This is my first post, so please forgive me if this question has been
OK, I know that this has been asked previously, so please forgive me for
I know this question has with out any doubt been asked a whole lot
I am a Scala novice so forgive me if this is a stupid question,
Please forgive me if this has been answered before. I'm looking for some advice

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.