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

Why is Tuple only specialized for Int, Long and Double?

1 reply
Jesper
Joined: 2010-06-13,
User offline. Last seen 2 years 17 weeks ago.
Hello everybody,
I'm working on a computation-intensive program where I use Tuple2[Float, Float] a lot. I looked at the source code of the Scala library (2.8.0.final) and I see that Tuple2 is partially specialized:
case class Tuple2[@specialized(Int, Long, Double) +T1, @specialized(Int, Long, Double) +T2](_1:T1,_2:T2)  extends Product2[T1, T2]
It's not specialized for Float, so my program doesn't take advantage of the specialization.
Why are tuples only specialized for Int, Long and Double and not for the other "primitive" types? And why the choice for Int, Long and Double?
-- Jesper de Jong | jespdj@gmail.com
David Flemström
Joined: 2009-08-10,
User offline. Last seen 42 years 45 weeks ago.
Re: Why is Tuple only specialized for Int, Long and Double?
If a class is specialized for every primitive type twice, there'll have to be 100 specialization classes (10 * 10 type combinations) for that class. There are currently 9 (3 * 3 type combinations) which is much more manageable. Adding Float would make that number into 16, which still would be OK in my humble opinion, and it would also add some symmetry (32-bit integrals and fractionals, 64-bit integrals and fractionals), so I don't know why it hasn't been done (there must be some practical reason).

On Fri, Jul 30, 2010 at 7:37 AM, Jesper de Jong <jespdj@gmail.com> wrote:
Hello everybody,
I'm working on a computation-intensive program where I use Tuple2[Float, Float] a lot. I looked at the source code of the Scala library (2.8.0.final) and I see that Tuple2 is partially specialized:
case class Tuple2[@specialized(Int, Long, Double) +T1, @specialized(Int, Long, Double) +T2](_1:T1,_2:T2)  extends Product2[T1, T2]
It's not specialized for Float, so my program doesn't take advantage of the specialization.
Why are tuples only specialized for Int, Long and Double and not for the other "primitive" types? And why the choice for Int, Long and Double?
-- Jesper de Jong | jespdj@gmail.com

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