- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Can this implicit conversion with implicit param work ?
Tue, 2011-11-29, 16:27
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)
====================================================================
Tue, 2011-11-29, 18:07
#2
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
>
>
Tue, 2011-11-29, 18:17
#3
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
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