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

The Archive Base Latest Questions

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

Consider the following typical Scala ‘pimp’ code: class PimpedA(a:A){ def pimp() = hi }

  • 0

Consider the following typical Scala ‘pimp’ code:

class PimpedA(a:A){
  def pimp() = "hi"
}
implicit def pimpA(a:A) = new PimpedA(a)

new A(){
  pimp()  //<--- does not compile
}

However, changing it to:

new A(){
  this.pimp()
}

Makes it work.
Shouldn’t it be the same to the Scala compiler?

EDIT : Is there any solution that can make it work without having to add the this.?

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

    In this case you should give compiler a hint that pimp() is not a random function. When you write

    this.pimp()
    

    compiler know there isn’t pimp function on class A so it’s an error and before giving up it searches implicit conversion in scope and finds it.

    pimpA(this).pimp()
    

    And when you just call pimp() compiler doesn’t know what object to pass to the pimpA(a: A) implicit function.

    UPDATE

    It is hard to understand what is your goal. I can only suggest to make PimpedA a typeclass (Pimp[T] in this example).

    trait Pimp[T] {
      def action(p: T): String
    }  
    
    implicit object PimpA extends Pimp[A] {
      override def action(p: A) = "some actions related to A"
    }
    
    def pimp[T: Pimp](p: T) = implicitly[Pimp[T]].action(p)
    
    class A {
      val foo = pimp(this)
    }
    
    scala> new A foo
    res2: String = some actions related to A
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider the following code snippet: class Test { public int Length{ get; set; }
Consider following code: ArrayList<Integer> aList = new ArrayList<Integer>(); aList.add(2134); aList.add(3423); aList.add(4234); aList.add(343); String tmpString
Consider following code: typedef SomeType type_t[2]; SomeType * arr1 = new type_t; //new or
please consider following code #include <iostream> using namespace std; class Digit { private: int
Consider a typical social networking website, which has more or less the following models:
Consider the following code which is typcial of many ChannelFactory examples: WSHttpBinding myBinding =
Consider following example : public class SomeBusinessLayerService : DataService<MyEntityContainer> { [WebInvoke] void DoSomething(string someParam)
Consider following class class test { public: test(int x){ cout<< test \n; } };
Consider following SWT code example: http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet151.java?view=co How can I separate the inline defined class?
Please consider following code: 1. uint16 a = 0x0001; if(a < 0x0002) { //

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.