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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:29:46+00:00 2026-05-20T12:29:46+00:00

Is there a way to make this work (Scala 2.8.1): class A class B

  • 0

Is there a way to make this work (Scala 2.8.1):

class A
class B
def f(implicit b: B) {}
implicit val a = new A
implicit def aToB(a: A) = new B
f(a) // works ok
f // error: could not find implicit value for parameter b: B

Actually my problem is with Lift’s (2.2) dependency injection, i’m trying to convert Vendor[T] to T and implicitly require it in a class constructor without adding imports after each val:

object DependencyFactory extends Factory {
  implicit def vendorToVal[T](vendor: Vendor[T]): T = vendor.vend

  implicit val db = new FactoryMaker[DbAccess](Model) {}
  //uncommenting the following line makes it work, but can we avoid it? 
  //import db._
  implicit val userStore = new FactoryMaker[UserStore](new UserStore) {}
}

Where UserStore is:

class UserStore(implicit db: DbAccess)

Am i doing something wrong?

UPDATE

Thanks to Easy Angel for answering the first part. But it doesn’t solve my Lift DI problem because it turns out that there is an opposite conversion in scope (from T to Vendor[T]) and having those both leads to ‘error: diverging implicit expansion’.

Can it be solved?

UPDATE2

Wow one more problem after previous: having a conversion from some Container[T] to T with implicit instance of Container[U] in scope and a function with implicit parameter U leads to ‘diverging implicit expansion’ too:

class A
case class Vendor[T](v: T)
def f(implicit a: A) {}
implicit val vendor = Vendor(new A)
implicit def vendorToVal[T](implicit v: Vendor[T]) = v.v
f

Any hints?

  • 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-20T12:29:47+00:00Added an answer on May 20, 2026 at 12:29 pm

    You almost made it. You only need to declare a implicit:

    implicit def aToB(implicit a: A) = new B
    

    In this case compiler tries to find some implicit B for the first implicit argument of f and it finds aToB. Than compiler ties to satisfy aToB‘s requirement (implicit a: A) and finds your implicit val a.

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

Sidebar

Related Questions

Is there a way to make this work? (Scala 2.8.1) class A def f(implicit
Is there any way to make this work in Java? public static void change(List<?
Is there a way to make this code work? LogonControl.java @Audit(AuditType.LOGON) public void login(String
MyClass c = 10; Is there any way to make this code work? I
Is there any better way to make this query work? I'm looking for a
Is there a way to make a class such this one: class DB extends
Is there any way to make this work with a switch, syntactically? switch(i){ case
Is there a way to make this work correctly with a case when? field
Why won't this work in Oracle? Is there a way to make this work?
is there any way to make this work? I hope you'll get the idea,

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.