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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T13:53:23+00:00 2026-06-15T13:53:23+00:00

In the book Scala in Depth . There’s this example of implicit scoping as

  • 0

In the book Scala in Depth . There’s this example of implicit scoping as follows:

scala> object Foo {
     | trait Bar
     | implicit def newBar = new Bar {
     |   override def toString = "Implicit Bar"
     | }
     | }
defined module Foo

scala> implicitly[Foo.Bar]
res0: Foo.Bar = Implicit Bar

My question here is how did implicitly find the implementation of the trait Bar in the above given example? I think I am a little confused by how implicitly works

  • 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-15T13:53:25+00:00Added an answer on June 15, 2026 at 1:53 pm

    Apparently, for Foo.Bar, it works like Foo#Bar, i.e., if T is a type projection S#U, the parts of S as well as T itself are in implicit scope (7.2 of the spec, but see usual resources on implicit scope, such as you’re already consulting). (Update: Here is such a resource. It doesn’t illustrate exactly this case, and whether a real example would look as artificial.)

    object Foo {
      trait Bar
      implicit def newBar = new Bar {
        override def toString = "Implicit Bar"
      }
    }
    
    class Foo2 {
      trait Bar
      def newBar = new Bar {
        override def toString = "Implicit Bar"
      }
    }
    object Foo2 {
      val f = new Foo2
      implicit val g = f.newBar
    }
    
    object Test extends App {
      // expressing it this way makes it clearer
      type B = Foo.type#Bar
      //type B = Foo.Bar
      type B = Foo2#Bar
      def m(implicit b: B) = 1
      println(implicitly[B])
      println(m)
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Reading the Scala by Example book and there is this example when Martin explains
In Scala (2.7), if I have this function: def foo(args: Array[String]) = for (arg
In the book Programming in Scala from Martin Odersky there is a simple example
In Chapter 9 of Programming In Scala, there is an example method like this:
I am reading the Scala in Examples book and almost every example there has
While going through the book Scala for the Impatient , I came across this
I'm a newbie to scala. I'm trying an example from the book Programming Scala.
This is the code I used from a book... import scala.actors.Actor._ val countActor =
The following example is from the book 'Programming in Scala'. Given a class 'Rational'
Using Scala's command line REPL: def foo(x: Int): Unit = {} def foo(x: String):

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.