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

  • Home
  • SEARCH
  • 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 6699031
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:38:50+00:00 2026-05-26T06:38:50+00:00

So basically I want to write a function that can be written like this:

  • 0

So basically I want to write a function that can be written like this:

{ println(_) } =: thing

Here I want it to actually do thing.=:(println(_)). Lets say for the sake of argument that =: has the following implementation:

def =:(block : Int => Any) {
    block(5)
}

So I try calling it the above way and I get:

<console>:10: error: type mismatch;
   found   : Unit
   required: Int => Any
             println(_) =: thing

I then try doing this:

thing.=:(println(_))

This way I get a nice 5 printed to the terminal. I then tried this:

{ value => println(value) } =: thing

This again failed and told me there is a “missing parameter type”. I’m guessing that this is because Scala tries to parse/compile the function argument first in this case and doesn’t guess the type as it would (I’m completely guessing here) when it is called the more conventional way (with the dot operator).

Could anyone shed more light on the problems here and also maybe suggest the best way to achieve something close to my original goal?

P.S. Sorry about the title. I’ll rename it once I have a better understanding of the problem.

  • 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-26T06:38:50+00:00Added an answer on May 26, 2026 at 6:38 am

    Type inference works left-to-right, even if symbolic method names of the #: form end up working right to left. You can use a helper method if you actually only have one type:

    def let(fi: Int => Any) = fi
    case class Thing(i: Int) {
      def =:(f: Int => Any) = f(i)
    }
    
    scala> let(_+2) =: Thing(5)
    res4: Any = 7
    

    but this isn’t an entirely satisfactory solution if you have many possible type signatures because you have to match the helper method name on the left to the required type on the right.

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

Sidebar

Related Questions

Basically I want to do this: Can I use a lambda function or std::function
I want to write a simple SMPP Server that basically forwards traffic to another
I basically want to do this in code: PersonList myPersonList; //populate myPersonList here, not
I want to write a rule in prolog, which basically says If a user
I'm trying to write my first iterator class / container type. Basically, I want
I basically want to do this: grep 'example.com' www_log > example.com.YYYY-MM-DD-H:i:S.log ...with of course
OK, first, I dont want any kind of flamewar here or anything like it.
First off, I know I can copy "this" on instantiation, but that doesn't work
I have a List of words I want to ignore like this one :
I'm trying to write a simple php function that will strip everything between two

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.