Open non opened 11 years ago
I don't understand why it will always box. Due to erasure, we will be unable to branch upon a Image[RGB]
vs a Image[RGBA]
at runtime. However, the image input/parsing function returns a separate ADT, LoadedImage
, that has distinct constructors for each parameterized type that it should return. Thus, the compiler should be able to know the type of of Image[RGB]
and invoke the specialized apply$mcI$sp
method.
Currently, if we write an implementation of Image[Int]
, scalac has no problem using specialization. Why should it (besides scalac implementation details) not be able to specialize on Image[RGB]
as well? Further, I think this should even work on totally generic Image[A : Pixel]
implementations; providing a Pixel[Int]
instance and calling apply results in the specialized version being called in the cases I tested.
Am I missing something here?
Even if the value class bugs are fixed, this will continue to box.
If it did not box, then (due to erasure) there's no way that you could have different behaviors for
Image[RGB]
versusImage[RGBA]
since they would both erase toInt
.If you want different behaviors (different type classes used for
A
for example), I think a better way to go is have a second type parameter and/or value parameter. This will let you grab different type class instances for "Int-as-RGB" versus "Int-as-Gray" while still preservingA=Int
for specialization purposes.