I'd prefer something like:Reified[T]Reified[Class[T]]Reified[Array[T]]
Having classOf and typeOf as incantations totally rocks!!
Even though arrayOf does not feel like an excellent name for an implicit summoning incantation, on a second thought, we dont need an incantation for ArrayTag per se. We only need an array creator, and arrayOf[T](dim) looks perfect for the job.
But typeOf[T]... Wow, just wow. Super duper cool!!
One thing we should also evaluate is naming of incantations to summon these descriptors, e.g. typeTag[T] or typeable[T].In this light I tend to like 1 better, because, imho, incantations for 1 sound a bit better than for 2.
On Sun, May 20, 2012 at 6:28 PM, Eugene Burmako <eugene....@epfl.ch> wrote:
One thing we should also evaluate is naming of incantations to summon these descriptors, e.g. typeTag[T] or typeable[T].In this light I tend to like 1 better, because, imho, incantations for 1 sound a bit better than for 2.Let's not concentrate on incantations. They are for the specialist and a specialist will write whatever is required, including implicitly[Typeable[T]], which is probably perfectly fine. What matters is all the user code that now decorates types with ClassManifest or Manifest and will have to decorate types with the new names.
On Sun, May 20, 2012 at 7:19 PM, martin odersky <martin....@epfl.ch> wrote:
On Sun, May 20, 2012 at 6:28 PM, Eugene Burmako <eugene....@epfl.ch> wrote:
One thing we should also evaluate is naming of incantations to summon these descriptors, e.g. typeTag[T] or typeable[T].In this light I tend to like 1 better, because, imho, incantations for 1 sound a bit better than for 2.Let's not concentrate on incantations. They are for the specialist and a specialist will write whatever is required, including implicitly[Typeable[T]], which is probably perfectly fine. What matters is all the user code that now decorates types with ClassManifest or Manifest and will have to decorate types with the new names.def foo[A : ArrayOf] == implicitly[ArrayOf[A]] == arrayOf[A](dim) == Array[A](dim) (could be deprecated)def foo[C : ClassOf] == implicitly[ClassOf[C]] == classOf[C] (with an implicit from classOf[C] => Class[C])def foo[T : TypeOf] == implicitly[TypeOf[T]] == typeOf[T]
Of the original proposal I like *Tag best.
+1.
I also think the search for something that doubles as a noun and an
adjective is misguided.
Just a vote from the user's point of view:
In any case, let's retain context bounds: [T : X] with X to be decided
on. Things like X[T] would be rather confusing.
As to X, I feel the 'Tag' suffix is vague. Instead, I'd prefer a
suffix capable expressing what this context bound is good for. Is it
used for reflecting or rather reifying T? For instance if you claim
it's purpose is closer to 'reflect' T, just go with Dave's last
suggestion:
[T: TypeReflectable] or even [T: Reflectable]
[T: ClassReflectable]
[T: ArrayReflectable]
If it's closer to 'reification' replace 'Reflectable' with
'Reifyable'.
[T: TypeReifyable] or even [T: Reifyable]
[T: ClassReifyable]
[T: ArrayReifyable]
+1
Knowing reify implies you've lived in java land for a bit. When my publisher asked about the word I did a survey of friends. Reify is a great word, but not as well known as you might guess.
ArraySeen[T] = an Array of T has been seen
"The compiler has seen that Arrays of Type T can be created".
"The compiler Knows an Array[T] can be created"
Scala 2.10 will introduce a new set of types that will eventually replace manifests. The new-style manifests fulfill similar roles to what Manifest/ClassManifest/OptManifest do now, yet are cleanly integrated with reflection. It was not possible to do that with the old style of manifests, and neither was it possible to migrate manifests safely to the new style. That's why for 2.10, old-style manifests will exists together with the new types, but will be deprecated The compiler will in any case happily infer either type for you, depending on what you specified.
There's still a question on what the new types should be named. Just to set the context, we picked "Manifest" as a name before because it can be used as an adjective. So the typical usage as a context bound, as in[T: Manifest]reads will, because it suggests that "Manifest" is a property of the type "T". "ClassManifest" works slightly less well, though. But anyway, these names are no longer available, and we need new ones.I wanted to get your opinion on what naming scheme you prefer. There are essentially three variants. In current trunk, we use the following names:Alternative 1:
[T: TypeTag] Instances of type T come with a descriptor that describes their whole type. This is analogous to Manifest in 2.8/2.9.[T: ClassTag] Instances of type T come with a descriptor that describes their erasure in a top-level Java class. This is analogous to ClassManifest in 2.8/2.9.[T: ArrayTag] It is possible to form arrays with instances of type T as elements. This is the same as ClassManifest in 2.8/2.9; it has been split off in 2.10 because some platforms (e.g. GWT) do not know Java classes, yet can still form arrays.All of that is more or less fine, except that none of the names above are adjectives. So the context bounds do not read very well. I also don't like the slightly different signification of ArrayTag from the others. TypeTag, ClassTag tell you about descriptors that come with the type, whereas ArrayTag means that you can form an array from elements of the type. Prompted by Simon PJ's Scala Days talk, where he showed "Typeable" as a name for something in Haskell that's similar to a manifest, I started to think of an alternative:Alternative 2a:[T: Typeable] Instances of type T come with a descriptor that describes their whole type.[T: Classable] Instances of type T come with a descriptor that describes their erasure in a top-level Java class.[T: Arrayable] Instances of type T can be aligned in an array.I personally like that naming scheme because they are all words in the english dictionary and have the right connotations. But "classable" and "arrayable" are pretty uncommon english words and native speakers such as Miles found their use "ghastly" ;-). I believe in particular "classable" is contentious as a term. So to be slightly less contentions we could also do
Alternative 2b:[T: Typeable][T: Classifiable][T: Arrayable]
"Classifiable" is a slightly longer word than "classable" and to my eyes not as directly connected with the meaning of runtime class. But but it's more familiar.So, what do you think? I am trying to get some feedback on this, in particular from native english speakers (but not only from them). You can simply respond with 1/2a/2b depending on which option you like best, or you can argue for one of the options, or maybe even propose yet another naming scheme (although we went through this already and I really would like to keep the current discussion focussed).Cheers
Reify isn't a concept you need a word for in this instance IMHO.
Since reifying is making an abstract concept a real thing, isn't that what you're doing I'd you take in a Class or a Type? I get a first-class object I can use that represents the abstract type. We reify things all the time in c.s.
It's only with generics and java VM vs. .net where the word reify holds a particular significance that is *less* than the meaning of the word.
The object passed is a reified type not the verb of reifying the type. The compiler does the reification. All I need to know is at run time I have an instance of a Type, which is not a normal run time thing.
So if you want reify in the name:
ReifiedType, ReifiedClass and that falls over for array.
I'm still pushing for:
ArrayBuilder[T]
Class[T]
Type[T]
Why add extraneous implementation details?
It's not ClosedFunction1 it's just Function1. The closure is computed by the compiler and I deal with a value of a function that happened to be generated using some closure computation. Also not every Function is actually a closure...
Same argument for reify. Note: you potentially could construct values of Type by hand, where reification doesn't play any role.
Class[T] sounds nice. I mean, the real java.lang.Class.
However there is a problem with Type. First, our Type is not polymorphic, and second, reified types are essentially type factories, not types. But I like the idea a lot.
On May 21, 2012 2:51 PM, "Josh Suereth" <joshua....@gmail.com> wrote:Reify isn't a concept you need a word for in this instance IMHO.
Since reifying is making an abstract concept a real thing, isn't that what you're doing I'd you take in a Class or a Type? I get a first-class object I can use that represents the abstract type. We reify things all the time in c.s.
It's only with generics and java VM vs. .net where the word reify holds a particular significance that is *less* than the meaning of the word.
The object passed is a reified type not the verb of reifying the type. The compiler does the reification. All I need to know is at run time I have an instance of a Type, which is not a normal run time thing.
So if you want reify in the name:
ReifiedType, ReifiedClass and that falls over for array.
I'm still pushing for:
ArrayBuilder[T]
Class[T]
Type[T]Why add extraneous implementation details?
It's not ClosedFunction1 it's just Function1. The closure is computed by the compiler and I deal with a value of a function that happened to be generated using some closure computation. Also not every Function is actually a closure...
Same argument for reify. Note: you potentially could construct values of Type by hand, where reification doesn't play any role.
On May 21, 2012 8:31 AM, "Peter Empen" <peter...@arcor.de> wrote:
>
> @Martin
> > >> My issue w...
Is the improved clarity of this convention outweighed by the cognitive burden of the shadowed names?
We can generate java.lang.Class[T] directly instead of wrapping it. That is what I especially like about this idea!
Also, if they absolutely must be adjectives, why not "TypeTagged", "ClassTagged", "ArrayTagged"?
Sure why not
And typeOf vs classOf ;-)
Speaking of ArrayBuilder, Martin said that we definitely need a different name, because we already have an unrelated ArrayBuilder in stdlib.
Decoupling array creation from the java reflection seems to be a good idea.For example, Greg's ScalaGWT stuff doesn't know anything about classes and erasures, but it still wants to create arrays.
On 21 May 2012 19:18, √iktor Ҡlang <viktor...@gmail.com> wrote:Why do we need an ArrayX? Java has java.lang.reflect.Array, which is used to dynamically create arrays, so we could simply have a scala.reflect.Array, which takes an implicit class for the component type?Cheers,√On Mon, May 21, 2012 at 7:09 PM, Kevin Wright <kev.lee...@gmail.com> wrote:
ArrayMaker, it sounds at least 10x morse awesome than ArrayFactoryOn 21 May 2012 17:22, Grzegorz Kossakowski <grzegorz.k...@gmail.com> wrote:
ArrayFactory?On 21 May 2012 18:18, Eugene Burmako <eugene....@epfl.ch> wrote:
Speaking of ArrayBuilder, Martin said that we definitely need a different name, because we already have an unrelated ArrayBuilder in stdlib.--
Grzegorz Kossakowski
--
Viktor Klang
Akka Tech Lead
On Mon, May 21, 2012 at 8:36 PM, Eugene Burmako <eugene....@epfl.ch> wrote:
Decoupling array creation from the java reflection seems to be a good idea.
For example, Greg's ScalaGWT stuff doesn't know anything about classes and erasures, but it still wants to create arrays.
I suspect in his case he'll be just fine with Object[]?
On 21.05.2012 21:14, √iktor Ҡlang wrote:Perhaps one wants to have pieces of code shared? That would be the explanation why ArrayX is needed. Well, if this is not the case (need for shared code), does the compiler require the witness for array creation in ScalaGWT? (would be nice if this were not necessary).
On Mon, May 21, 2012 at 8:36 PM, Eugene Burmako <eugene....@epfl.ch> wrote:
Decoupling array creation from the java reflection seems to be a good idea.
For example, Greg's ScalaGWT stuff doesn't know anything about classes and erasures, but it still wants to create arrays.
I suspect in his case he'll be just fine with Object[]?
On Mon, May 21, 2012 at 8:36 PM, Eugene Burmako <eugene....@epfl.ch> wrote:Decoupling array creation from the java reflection seems to be a good idea.For example, Greg's ScalaGWT stuff doesn't know anything about classes and erasures, but it still wants to create arrays.I suspect in his case he'll be just fine with Object[]?
I believe you're trivializing it.Everywhere in Scala the compiler requires a ClassManifest to make arrays. Rather than *fight* the compiler, it'd be nice to have a smaller surface area to replace Array creation, specifically the part that creates "ArrayTag". That way, you have to touch less code to make Scala compiler to Javascript.It's not about "being ok with Object[]", but having code that using implicit ClassManfiest/Manifest just to generate arrays not get in the way of generating JavaScript.
On Mon, May 21, 2012 at 9:35 PM, Josh Suereth <joshua....@gmail.com> wrote:
I believe you're trivializing it.Everywhere in Scala the compiler requires a ClassManifest to make arrays. Rather than *fight* the compiler, it'd be nice to have a smaller surface area to replace Array creation, specifically the part that creates "ArrayTag". That way, you have to touch less code to make Scala compiler to Javascript.It's not about "being ok with Object[]", but having code that using implicit ClassManfiest/Manifest just to generate arrays not get in the way of generating JavaScript.I think you misunderstood me. My point is that if you want to be Class-agnostic, you can't really work with arrays, since on the JVM they're very tightly knit to classes.
On Mon, May 21, 2012 at 9:41 PM, √iktor Ҡlang <viktor...@gmail.com> wrote:On Mon, May 21, 2012 at 9:35 PM, Josh Suereth <joshua....@gmail.com> wrote:
I believe you're trivializing it.Everywhere in Scala the compiler requires a ClassManifest to make arrays. Rather than *fight* the compiler, it'd be nice to have a smaller surface area to replace Array creation, specifically the part that creates "ArrayTag". That way, you have to touch less code to make Scala compiler to Javascript.It's not about "being ok with Object[]", but having code that using implicit ClassManfiest/Manifest just to generate arrays not get in the way of generating JavaScript.I think you misunderstood me. My point is that if you want to be Class-agnostic, you can't really work with arrays, since on the JVM they're very tightly knit to classes.But I believe for Javascript generation via GWT it's different. Greg should be able to give details.
What's your take on the following:
scala.reflect.Type[T]java.lang.Class[T]
so:
def foo[T : Type]def foo[C : Class]
Then Array.apply() can simply use a Class-witness and use java.lang.reflect.Array?
So no need for ArrayBuilder/ArrayInfo/ArrayMaker/Arrayer/whathaveyou
So things fall into two categories instead of three?
Or I am just completely missing some key piece here and everyone's just flabbergasted at my insanity?
On Mon, May 21, 2012 at 9:21 PM, Miles Sabin <mi...@milessabin.com> wrote:Obvious, but worth flagging up anyway: if you want both reified type
>> scala.reflect.Type[T]
>> java.lang.Class[T]
>>
>> so:
>>
>> def foo[T : Type]
>> def foo[C : Class]
>>
>> Then Array.apply() can simply use a Class-witness and use
>> java.lang.reflect.Array?
>>
>> So no need for ArrayBuilder/ArrayInfo/ArrayMaker/Arrayer/whathaveyou
>>
>> So things fall into two categories instead of three?
>>
>> Or I am just completely missing some key piece here and everyone's just
>> flabbergasted at my insanity?
>
> +1
>
> If you are then so am I. This is the best suggestion I've seen so far :-)
info *and* the means of constructing values then you just ask for
both,
def foo[T : Type : Class] ...
Cheers,
Miles
--
Miles Sabin
tel: +44 7813 944 528
gtalk: mi...@milessabin.com
skype: milessabin
g+: http://www.milessabin.com
http://twitter.com/milessabin
http://underscoreconsulting.com
http://www.chuusai.com
What's your take on the following:scala.reflect.Type[T]java.lang.Class[T]so:def foo[T : Type]def foo[C : Class]Then Array.apply() can simply use a Class-witness and use java.lang.reflect.Array?So no need for ArrayBuilder/ArrayInfo/ArrayMaker/Arrayer/whathaveyouSo things fall into two categories instead of three?Or I am just completely missing some key piece here and everyone's just flabbergasted at my insanity?
What an epic thread!On 21 May 2012 21:55, √iktor Ҡlang <viktor...@gmail.com> wrote:What's your take on the following:scala.reflect.Type[T]java.lang.Class[T]so:def foo[T : Type]def foo[C : Class]Then Array.apply() can simply use a Class-witness and use java.lang.reflect.Array?So no need for ArrayBuilder/ArrayInfo/ArrayMaker/Arrayer/whathaveyouSo things fall into two categories instead of three?Or I am just completely missing some key piece here and everyone's just flabbergasted at my insanity?Before I dive into problem with GWT (and with any Scala2JS compiler) related to Arrays let me ask a question about above proposal. What about:def foo[T : Class](x: T): Array[T] = Array(2)(x) //array with x as initial value everywheredef bar[C: Class](x: C): Array[Array[C]] = {val a = Array(1)(x)foo(a) //what should be passed as an implicit arg? here T = Array[C] and we have only Class[C] and not Class[Array[C]]}
--
Grzegorz Kossakowski
On Mon, May 21, 2012 at 9:48 PM, Grzegorz KossakowskiIn Java you'd only need Class<C> to create C[], C[][], etc. (just use
<grzegorz.k...@gmail.com> wrote:
> Before I dive into problem with GWT (and with any Scala2JS compiler) related
> to Arrays let me ask a question about above proposal. What about:
>
> def foo[T : Class](x: T): Array[T] = Array(2)(x) //array with x as initial
> value everywhere
>
> def bar[C: Class](x: C): Array[Array[C]] = {
> val a = Array(1)(x)
> foo(a) //what should be passed as an implicit arg? here T = Array[C] and
> we have only Class[C] and not Class[Array[C]]
> }
java.lang.reflect.Array.newInstance with the appropriate number of
dimensions), so why would we need anything more here?
Cheers,
Miles
--
Miles Sabin
tel: +44 7813 944 528
gtalk: mi...@milessabin.com
skype: milessabin
g+: http://www.milessabin.com
http://twitter.com/milessabin
http://underscoreconsulting.com
http://www.chuusai.com
In Java you'd only need Class<C> to create C[], C[][], etc. (just use
java.lang.reflect.Array.newInstance with the appropriate number of
dimensions), so why would we need anything more here?
In Java you'd only need Class<C> to create C[], C[][], etc. (just use
java.lang.reflect.Array.newInstance with the appropriate number of
dimensions), so why would we need anything more here?These are the droids you're looking for: http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Array.html#newInstance(java.lang.Class, int...)
--
Grzegorz Kossakowski
Hmm ... good point.On Mon, May 21, 2012 at 10:13 PM, Grzegorz Kossakowski
<grzegorz.k...@gmail.com> wrote:
> On 21 May 2012 23:09, Miles Sabin <mi...@milessabin.com> wrote:
>>
>>
>> In Java you'd only need Class<C> to create C[], C[][], etc. (just use
>> java.lang.reflect.Array.newInstance with the appropriate number of
>> dimensions), so why would we need anything more here?
>
>
> That doesn't answer my question what implicit value should be passed when
> foo is called, right?
Can we live with the overheads of this,
implicit def wrap[T : Class] : Class[Array[T]] =
java.lang.reflect.Array.newInstance(implicitly[Class[T]], 0).
getClass.asInstanceOf[Class[Array[T]]]
which given,
implicit def fakeImplicitClass[T : ClassManifest] =
classManifest[T].erasure.asInstanceOf[Class[T]]
Perhaps this is all to subtle for me, but remember that GWT compiles *the same code* once into js and once into bytecode. I see the attraction of substituting in a different type alias in the two phases, but will this not make everything invoking operations on things typed by this type alias break on one or the other of the compilation phases? If you refer to any operation available on Class then this won't work in the js target, and if you refer to any operation available on ArrayFactory then that won't work in the bytecode target. So, you really do need some interface here to encapsulate this target-specific shim, and given the nature of such things, this interface should have a minimal cross-section and minimal (or absent) coupling to features that may themselves be target-dependent. Of course, under the hood the target-specific implementation of this interface will be very much coupled to the target.
On Tue, May 22, 2012 at 12:47 AM, Grzegorz KossakowskiWhat currently happens when someone references ClassManifest#erasure?
<grzegorz.k...@gmail.com> wrote:
> I cannot replace Class with something completely different because Class
> itself (along with getName) is supported so that code would break. Also, GWT
> supports something called "devmode" when it just runs your app on JVM and
> transmits things like dom calls through RPCs to the browser.