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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:06:14+00:00 2026-05-30T11:06:14+00:00

I want to add new function extra to library class (orig for example). orig.extra(rich.Arg())

  • 0

I want to add new function “extra” to library class (“orig” for example).

orig.extra(rich.Arg()) // <- like this

If I comment 1st implicit conversion than I get error. I read Scala specification, and suspect that there are two places for implicit lookup:

  1. companion object of argument

  2. object that holds argument

Any tips? Unfortunately most official documentation about implicit is not very helpful and stack overflow search too.

scala> object container {
 |   //implicit def orig2rich(o: orig.type) = new { def extra(a: rich.Arg) = "extra" }
 |   object rich {
 |     implicit def orig2rich(o: orig.type) = new { def extra(a: Arg) = "extra" }
 |     case class Arg(val some: String = "some")
 |     object Arg {
 |       implicit def orig2rich(o: orig.type) = new { def extra(a: Arg) = "extra" }
 |     }
 |   }
 |   object orig {
 |     def standard(s: String) = "standard"
 |   }
 |   orig.extra(rich.Arg())
 | }
<console>:35: error: value extra is not a member of object container.orig
     orig.extra(rich.Arg())

EDIT

I read Where does Scala look for implicits?, very useful. And find my case – Implicit scope of an argument’s type

Example that worked:

object container {
class A(val n: Int) {
  def +(other: A) = new A(n + other.n)
}
object A {
  implicit def fromInt(n: Int) = new A(n)
}

// This becomes possible:
1 + new A(1)
// because it is converted into this:
A.fromInt(1) + new A(1)
}

Change it a bit, just function name (what I actually want), and 🙁 oops

object container {
class A(val n: Int) {
  def hello(other: A) = new A(n + other.n)
}
object A {
  implicit def fromInt(n: Int) = new A(n)
}

// This becomes possible:
1.hello(new A(1))
// because it is converted into this:
A.fromInt(1).hello(new A(1))
}

<console>:16: error: value hello is not a member of Int
       1.hello(new A(1))

Scala version 2.9.1.r0-b20120114153402 (OpenJDK 64-Bit Server VM, Java 1.6.0_22).

It is a bit confusing. I tried to mix

7.3 Views

  1. In a selection e.m with e of type T , if the selector m does not denote a member
    of T . In this case, a view v is searched which is applicable to e and whose result
    contains a member named m. The search proceeds as in the case of implicit
    parameters, where the implicit scope is the one of T . If such a view is found,
    the selection e.m is converted to v (e ).m.
  2. In a selection e.m(args) with e of type T , if the selector m denotes some mem-
    ber(s) of T , but none of these members is applicable to the arguments args. In
    this case a view v is searched which is applicable to e and whose result con-
    tains a method m which is applicable to args. The search proceeds as in the
    case of implicit parameters, where the implicit scope is the one of

IMHO it is not possible

Thank you

  • 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-30T11:06:16+00:00Added an answer on May 30, 2026 at 11:06 am

    scala is applying implicit conversions that are visible in the same scope, so you can just add line

    import rich.orig2rich
    

    or

    import rich._
    

    This code will work

    object container {
    
      //implicit def orig2rich(o: orig.type) = new { def extra(a: rich.Arg) = "extra" }
      object rich {
        implicit def orig2rich(o: orig.type) = new {
          def extra(a: Arg) = "extra"
        }
    
        case class Arg(val some: String = "some")
    
        object Arg {
          implicit def orig2rich(o: orig.type) = new {
            def extra(a: Arg) = "extra"
          }
        }
    
      }
    
      object orig {
        def standard(s: String) = "standard"
      }
    
      import rich.orig2rich
    
      def test = orig.extra(rich.Arg())
    }
    
    println(container.test)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to add a new tab page for every newly opened form. Example:
I want to add a new feature in a wxPython class. I also want
I am developing picture viewer application and I want to add new function to
I need to add a new method to my swig template class, for example:
I want to add a new time-field to a an existing MySQL-table that is
I want to add a new filter to the Project Explorer, to hide from
I want to add a new Stage called field to the default one (i
I want to give users the possibility to dynamically add new columns at the
I am new to iphone development.I want to add RegexKitLite framework.I have downloaded the
I want to add days to a date to get a new date in

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.