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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:27:02+00:00 2026-06-12T01:27:02+00:00

Suppose an outer class with an inner composite of two inner classes: class Outer(val

  • 0

Suppose an outer class with an inner composite of two inner classes:

class Outer(val times: Int) {

  class Inner(val count: Int)
  object Inner {
    def apply(i: Int) = new Inner(i)
  }

  class InnerWrap(val i: Inner)
  object InnerWrap {
    def apply(i: Inner) = new InnerWrap(i)
  }
  def method(i: Inner) = i.count * times
}
object Outer {
  def apply(times: Int) = new Outer(times)
}

class PathDependentExpl {
  val o = new Outer(3)
  val i = o.Inner(2)
  val p = new Outer(5)
  val j = p.Inner(3)
  println(o.method(i))
  println(p.method(j))
}

All nice and dandy. We even have compiler protection against feeding inners from one Outer to methods of another Outer through path-dependent types.

But the syntax is a little annoying. I want to be able to write something like

implicit val p = new Outer(5)
val k = Inner(3) // same as p.Inner(3)
val l = InnerWrap(Inner(3))

…omitting the outer instance for the block where the implicit is valid. So I rush adding delegate methods with the Outer object as an implicit parameter.

object Outer {
  def apply(times: Int) = new Outer(times)
  def Inner(c: Int)(implicit o: Outer) = o.Inner(c)
  def InnerWrap(i: o.Inner)(implicit o: Outer) = o.InnerWrap(i)
}

That last InnerWrap definition yields: “illegal dependent method type: parameter appears in the type of another parameter in the same section or an earlier one”, which actually makes sense. I tried def InnerWrap[O <: Outer#Inner](i: O)(implicit o: Outer) = o.InnerWrap(i) and other variants to no avail.

Question is, how can I still get to use the cleaner syntax? How can the declaration of InnerWrap in object Outer can be made to accept o.Inners or equivalent?

  • 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-12T01:27:03+00:00Added an answer on June 12, 2026 at 1:27 am

    As I noted in a comment above, it’s possible to import the objects (or methods) you need from p, which may give you the clean syntax you’re looking for:

    scala> val p = new Outer(5)
    p: Outer = Outer@4fe2fe5d
    
    scala> import p._
    import p._
    
    scala> val k = Inner(3)
    k: p.Inner = Outer$Inner@b90ffa7
    
    scala> val l = InnerWrap(Inner(3))
    l: p.InnerWrap = Outer$InnerWrap@3bd6bff7
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have the following python code: def outer(): string = def inner(): string
Suppose I have a static method of my class that returns an object of
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have an outer container of unknown fixed width, and an inner element,
Suppose I have: public class OuterClass() { public class InnerClass { public void someMethod(int
Suppose I have two lists of type MyCustomType , a class which could be
Suppose I have: <div id=outer onclick=thingsHappen()> <div id=inner></div> </div> When I click on outer
Suppose I have a simple model, such as Record: @Model public class Record {
Suppose I have two tables, - emp(empId number(1),empName varchar2(50)) and - manager(manId number(5),managerName varchar2(100))
Why the outer joins are in general slower than inner joins? I mean, independently

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.