This page is no longer maintained — Please continue to the home page at www.scala-lang.org

Can this implicit conversion with implicit param work ?

3 replies
Maxime Lévesque
Joined: 2009-08-18,
User offline. Last seen 42 years 45 weeks ago.

Hi, with the definitions below, the following conversion is not happening :

1.iAmABasket

If I change i2 for :

implicit def i2[A](a: A)(implicit bf: BasketFactory[A,_]):
Basket[A,_] = bf.create(a)

it will work, but what I want is precisely is that given one type (A =
Int) at the call site,
a second type is obtained (B = TARInt) based on the available implicit
BasketFactory[A,B]

Of course adding a second conversion :

implicit def i1(l: Int) = bf.create(l)

does the trick, but I'm wondering if there's a way to avoid this,
actually I'm curious
about the rule that I am breaking with regards to the type system.

Thanks

====================================================================

trait TARInt

trait Basket[A,B] {
def iAmABasket = {}
}

trait BasketFactory[A,B] {
def create(v: A): Basket[A,B] = sys.error("!")
}

implicit val bf = new BasketFactory[Int,TARInt] {
def create(v: Int): Basket[Int,TARInt] = sys.error("!")
}

implicit def i2[A,B](a: A)(implicit bf: BasketFactory[A,B]):
Basket[A,B] = bf.create(a)

====================================================================

Stefan Zeiger
Joined: 2008-12-21,
User offline. Last seen 27 weeks 4 days ago.
Re: Can this implicit conversion with implicit param work ?

On 2011-11-29 16:27, Maxime Lévesque wrote:
> Hi, with the definitions below, the following conversion is not happening :
>
> 1.iAmABasket

Meet my old friend SI-3346: https://issues.scala-lang.org/browse/SI-3346

Cheers,
Stefan

Maxime Lévesque
Joined: 2009-08-18,
User offline. Last seen 42 years 45 weeks ago.
Re: Can this implicit conversion with implicit param work ?

Nice to see it's flagged as major in Jira, i'll be watching this one !

Thanks

2011/11/29 Stefan Zeiger :
> On 2011-11-29 16:27, Maxime Lévesque wrote:
>>
>> Hi, with the definitions below, the following conversion is not happening
>> :
>>
>>   1.iAmABasket
>
> Meet my old friend SI-3346: https://issues.scala-lang.org/browse/SI-3346
>
> Cheers,
> Stefan
>
>

Stefan Zeiger
Joined: 2008-12-21,
User offline. Last seen 27 weeks 4 days ago.
Re: Can this implicit conversion with implicit param work ?

On 2011-11-29 17:52, Maxime Lévesque wrote:
> Nice to see it's flagged as major in Jira, i'll be watching this one !

Don't get your hopes up too high, Major is the default priority for bug
reports ;-)

-sz

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland