<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Native Type Support In Scala? Wish for 2.8</title>
	<atom:link href="http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/feed/" rel="self" type="application/rss+xml" />
	<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/</link>
	<description></description>
	<lastBuildDate>Tue, 03 Jan 2012 15:08:49 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Daniel Spiewak</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-207041</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Fri, 28 Nov 2008 04:19:29 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-207041</guid>
		<description>@Ricky

Neat idea.  I think you&#039;ll have to change &quot;in[Scopes.SINGLETON]&quot; to &quot;in[Scopes#SINGLETON]&quot;, but besides that I think it could be done.  This is a lot nicer than my companion object hack.

The one thing I would caution is that Manifest probably shouldn&#039;t be relied upon too heavily.  I don&#039;t remember the specifics, but there are some circumstances where generic types cannot be fully reified on the JVM (even using Manifest).</description>
		<content:encoded><![CDATA[<p>@Ricky</p>
<p>Neat idea.  I think you&#8217;ll have to change &#8220;in[Scopes.SINGLETON]&#8221; to &#8220;in[Scopes#SINGLETON]&#8220;, but besides that I think it could be done.  This is a lot nicer than my companion object hack.</p>
<p>The one thing I would caution is that Manifest probably shouldn&#8217;t be relied upon too heavily.  I don&#8217;t remember the specifics, but there are some circumstances where generic types cannot be fully reified on the JVM (even using Manifest).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206976</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Fri, 28 Nov 2008 02:54:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206976</guid>
		<description>class MyModule extends Module {
    def configure(binder: Binder) {
        binder.bind[Service]
            .to[ServiceImpl]
            .in[Scopes.SINGLETON]
    }
}

This is possible since Manifest hit Scala, though obviously you&#039;d have to wrap the Binder API to achieve it.</description>
		<content:encoded><![CDATA[<p>class MyModule extends Module {<br />
    def configure(binder: Binder) {<br />
        binder.bind[Service]<br />
            .to[ServiceImpl]<br />
            .in[Scopes.SINGLETON]<br />
    }<br />
}</p>
<p>This is possible since Manifest hit Scala, though obviously you&#8217;d have to wrap the Binder API to achieve it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206752</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Thu, 27 Nov 2008 21:48:47 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206752</guid>
		<description>&gt; As I’m more of a practical person, is
&gt; 
&gt; bind(Person)
&gt; 
&gt; using the Type, the Class or
&gt; the Meta-Object?

Depends on how you look at it (hence, James&#039;s point).  It certainly would not be the type, but it could be either the class (or more correctly, the *meta-class*) or the meta-object.

&gt; Would it then not be better to
&gt; access a class with Person as I
&gt; access an object with person
&gt; (and this is not about Meta-
&gt; Classes). What I can do with
&gt; this class reference is another
&gt; thing (call methods or not etc.)
&gt; I consider this much easier and
&gt; consistent.

So, if we were to use this syntax, what would this mean?

Person.getMethods()

Just for kicks, let&#039;s make it even worse in the declaration:

class Person { ... }

object Person {
  def getMethods() = ...
}

So does Person.getMethods() refer to classOf[Person].getMethods()?  Or is it a call to the getMethods() method in the Person singleton?</description>
		<content:encoded><![CDATA[<p>&gt; As I’m more of a practical person, is<br />
&gt;<br />
&gt; bind(Person)<br />
&gt;<br />
&gt; using the Type, the Class or<br />
&gt; the Meta-Object?</p>
<p>Depends on how you look at it (hence, James&#8217;s point).  It certainly would not be the type, but it could be either the class (or more correctly, the *meta-class*) or the meta-object.</p>
<p>&gt; Would it then not be better to<br />
&gt; access a class with Person as I<br />
&gt; access an object with person<br />
&gt; (and this is not about Meta-<br />
&gt; Classes). What I can do with<br />
&gt; this class reference is another<br />
&gt; thing (call methods or not etc.)<br />
&gt; I consider this much easier and<br />
&gt; consistent.</p>
<p>So, if we were to use this syntax, what would this mean?</p>
<p>Person.getMethods()</p>
<p>Just for kicks, let&#8217;s make it even worse in the declaration:</p>
<p>class Person { &#8230; }</p>
<p>object Person {<br />
  def getMethods() = &#8230;<br />
}</p>
<p>So does Person.getMethods() refer to classOf[Person].getMethods()?  Or is it a call to the getMethods() method in the Person singleton?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206749</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 27 Nov 2008 21:39:37 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206749</guid>
		<description>&quot;Sorry about all the rambling, long winded talk.&quot;

Ah, no, thanks for the long explanation.

As I&#039;m more of a practical person, is

bind(Person)

using the Type, the Class or the Meta-Object?</description>
		<content:encoded><![CDATA[<p>&#8220;Sorry about all the rambling, long winded talk.&#8221;</p>
<p>Ah, no, thanks for the long explanation.</p>
<p>As I&#8217;m more of a practical person, is</p>
<p>bind(Person)</p>
<p>using the Type, the Class or the Meta-Object?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Iry</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206745</link>
		<dc:creator>James Iry</dc:creator>
		<pubDate>Thu, 27 Nov 2008 21:32:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206745</guid>
		<description>List&lt;Person&gt; has nothing to do with the Person class it&#039;s about the Person type.  To see why, remember that you can have List[List[Person]] too, but there&#039;s no List[Person] class. Type != class.  

The closest you can come to accessing a class at runtime in Java or Scala is Person.class or classOf[Person] respectively.  But even that does not actually give you access to the class but to a metaobject.  This is true even in Groovy - it&#039;s just that Groovy supports dynamic metaprogramming such that having access to a metaobject is more-or-less like having access to the class.  Groovy also apparently gives you a handle to a metaobject whenever you use a class name in value position.

The confusing part in the whole discussion that in the right context, the static type, the class, and even the metaobject can each legitimately be called &quot;Person&quot; even though they are three different things from three different worlds.  Then, in Scala, we have the companion object - which perhaps could be the same as the metaobject, but probably not without breaking Java compatibility.  While we&#039;re at it, there&#039;s also a Person runtime type which a fourth concept which is accessible via isInstanceOf, asInstanceOf, and dynamic dispatch.  (as an aside, that&#039;s where you see the limitation of the runtime type systems in Java and Scala as compared to the static type system - the runtime type system might see something called simply List where the static type system has a type called List[Person]).  

It&#039;s also somewhat confusing that in Java runtime type and class are pretty parallel, but still should not be considered the same.  For instance null clearly has a runtime type and just as clearly has no associated class or metaobject (as an aside, it also has a static type which is a subtype of all reference types, even though that type isn&#039;t explicitly denotable in Java). 

Importantly, in languages with duck typing, runtime type is a much more sophisticated concept than Java allows - essentially the runtime types can be structural.  Groovy supports both structure and nominative runtime types.  Scala has an optional structural static type system and effectively has an optional structural dynamic type system accessible via casting, but it&#039;s significantly harder to use than Groovy/Ruby/etc.

In other languages there&#039;s even less of a relationship between class and runtime type - some &quot;OO&quot; languages like JavaScript don&#039;t even have classes but still have runtime types.

Sorry about all the rambling, long winded talk.</description>
		<content:encoded><![CDATA[<p>List&lt;Person&gt; has nothing to do with the Person class it&#8217;s about the Person type.  To see why, remember that you can have List[List[Person]] too, but there&#8217;s no List[Person] class. Type != class.  </p>
<p>The closest you can come to accessing a class at runtime in Java or Scala is Person.class or classOf[Person] respectively.  But even that does not actually give you access to the class but to a metaobject.  This is true even in Groovy &#8211; it&#8217;s just that Groovy supports dynamic metaprogramming such that having access to a metaobject is more-or-less like having access to the class.  Groovy also apparently gives you a handle to a metaobject whenever you use a class name in value position.</p>
<p>The confusing part in the whole discussion that in the right context, the static type, the class, and even the metaobject can each legitimately be called &#8220;Person&#8221; even though they are three different things from three different worlds.  Then, in Scala, we have the companion object &#8211; which perhaps could be the same as the metaobject, but probably not without breaking Java compatibility.  While we&#8217;re at it, there&#8217;s also a Person runtime type which a fourth concept which is accessible via isInstanceOf, asInstanceOf, and dynamic dispatch.  (as an aside, that&#8217;s where you see the limitation of the runtime type systems in Java and Scala as compared to the static type system &#8211; the runtime type system might see something called simply List where the static type system has a type called List[Person]).  </p>
<p>It&#8217;s also somewhat confusing that in Java runtime type and class are pretty parallel, but still should not be considered the same.  For instance null clearly has a runtime type and just as clearly has no associated class or metaobject (as an aside, it also has a static type which is a subtype of all reference types, even though that type isn&#8217;t explicitly denotable in Java). </p>
<p>Importantly, in languages with duck typing, runtime type is a much more sophisticated concept than Java allows &#8211; essentially the runtime types can be structural.  Groovy supports both structure and nominative runtime types.  Scala has an optional structural static type system and effectively has an optional structural dynamic type system accessible via casting, but it&#8217;s significantly harder to use than Groovy/Ruby/etc.</p>
<p>In other languages there&#8217;s even less of a relationship between class and runtime type &#8211; some &#8220;OO&#8221; languages like JavaScript don&#8217;t even have classes but still have runtime types.</p>
<p>Sorry about all the rambling, long winded talk.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206711</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 27 Nov 2008 19:39:03 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206711</guid>
		<description>@Daniel: I&#039;ve meant this more abstract. In a programming language there are things I need to access. Those are for example objects, fields, methods, functions and classes. Objects are usually accessed with names references, fields in Java are accessed by objectreference.fieldname etc. One needs ways to access these things to write software. classOf[] is just one way to access classes, .class is another way to access those, &lt;Person&gt; is another one (all with slightly different meanings, but all accessing the class). In assembler people accessed those things with register pointers.

&quot;One of the things I love about Scala (and I think everyone does) is the fact that the language design is remarkably consistent. There are a few wrinkles, but on balance, it’s better designed than any other language I’ve seen. The reason for this is they avoid things like “special magic convenient syntax for the edge case.&quot;

Would it then not be better to access a class with &lt;i&gt;Person&lt;/i&gt; as I access an object with &lt;i&gt;person&lt;/i&gt; (and this is not about Meta-Classes). What I can do with this class reference is another thing (call methods or not etc.) I consider this much easier and consistent.

&quot;The one seriously debilitating issue is this syntax introduces ambiguity in the grammar (between class literals and singleton objects).&quot;

A valid concern, but I&#039;m sure this could be solved.

@James:

&quot;post line 1, sentence 2: Currently in Scala you need to write classOf[Person] for the Java Person.class expression. &quot;

Oh, sorry, I&#039;ve just wanted to give people an impression what classOf[] does, not compare it to Person.class (I used .class because most readers will know what this does).

I&#039;ll digest the rest of your lengthy post after dinner ;-)</description>
		<content:encoded><![CDATA[<p>@Daniel: I&#8217;ve meant this more abstract. In a programming language there are things I need to access. Those are for example objects, fields, methods, functions and classes. Objects are usually accessed with names references, fields in Java are accessed by objectreference.fieldname etc. One needs ways to access these things to write software. classOf[] is just one way to access classes, .class is another way to access those, &lt;Person&gt; is another one (all with slightly different meanings, but all accessing the class). In assembler people accessed those things with register pointers.</p>
<p>&#8220;One of the things I love about Scala (and I think everyone does) is the fact that the language design is remarkably consistent. There are a few wrinkles, but on balance, it’s better designed than any other language I’ve seen. The reason for this is they avoid things like “special magic convenient syntax for the edge case.&#8221;</p>
<p>Would it then not be better to access a class with <i>Person</i> as I access an object with <i>person</i> (and this is not about Meta-Classes). What I can do with this class reference is another thing (call methods or not etc.) I consider this much easier and consistent.</p>
<p>&#8220;The one seriously debilitating issue is this syntax introduces ambiguity in the grammar (between class literals and singleton objects).&#8221;</p>
<p>A valid concern, but I&#8217;m sure this could be solved.</p>
<p>@James:</p>
<p>&#8220;post line 1, sentence 2: Currently in Scala you need to write classOf[Person] for the Java Person.class expression. &#8221;</p>
<p>Oh, sorry, I&#8217;ve just wanted to give people an impression what classOf[] does, not compare it to Person.class (I used .class because most readers will know what this does).</p>
<p>I&#8217;ll digest the rest of your lengthy post after dinner ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206706</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Thu, 27 Nov 2008 19:29:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206706</guid>
		<description>&gt; Actually makes f refer to the
&gt; companion object, not a first
&gt; class function. My bad.

Well, you were half-right.  :-)

case class Foo

def build(f: ()=&gt;Foo) = f()

build(Foo)

Companion objects for case classes extend their corresponding function types.  So your statement would have been accurate if you had said that &quot;f refers to a first class function which delegates to Foo&#039;s constructor.&quot;  Comes to about the same thing.</description>
		<content:encoded><![CDATA[<p>&gt; Actually makes f refer to the<br />
&gt; companion object, not a first<br />
&gt; class function. My bad.</p>
<p>Well, you were half-right.  :-)</p>
<p>case class Foo</p>
<p>def build(f: ()=&gt;Foo) = f()</p>
<p>build(Foo)</p>
<p>Companion objects for case classes extend their corresponding function types.  So your statement would have been accurate if you had said that &#8220;f refers to a first class function which delegates to Foo&#8217;s constructor.&#8221;  Comes to about the same thing.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pk11</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206699</link>
		<dc:creator>pk11</dc:creator>
		<pubDate>Thu, 27 Nov 2008 19:00:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206699</guid>
		<description>&gt;I’m really not sure why everybody refers to &gt;“Person.class”. Is this a Java vs. Scala thing? &gt;Is every post that mentions Scala and Java a &gt;Scala vs. Java thing? It wasn’t intended as such. 

sorry, i also misunderstood your issue! when you gave a scala guice example and called it noisy i immediately compared the scala version with the &#039;native&#039; java version. that&#039;s why i was talking about java&#039;s class literal.</description>
		<content:encoded><![CDATA[<p>&gt;I’m really not sure why everybody refers to &gt;“Person.class”. Is this a Java vs. Scala thing? &gt;Is every post that mentions Scala and Java a &gt;Scala vs. Java thing? It wasn’t intended as such. </p>
<p>sorry, i also misunderstood your issue! when you gave a scala guice example and called it noisy i immediately compared the scala version with the &#8216;native&#8217; java version. that&#8217;s why i was talking about java&#8217;s class literal.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Iry</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206698</link>
		<dc:creator>James Iry</dc:creator>
		<pubDate>Thu, 27 Nov 2008 18:58:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206698</guid>
		<description>One correction to my post

case class Foo
val f = Foo

Actually makes f refer to the companion object, not a first class function.  My bad.</description>
		<content:encoded><![CDATA[<p>One correction to my post</p>
<p>case class Foo<br />
val f = Foo</p>
<p>Actually makes f refer to the companion object, not a first class function.  My bad.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206688</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Thu, 27 Nov 2008 17:41:26 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206688</guid>
		<description>&gt; I didn’t want to refer to types as objects, but like objects.

I don&#039;t understand the distinction.  If I were formalizing a language with referable types, it would look exactly the same as a language where types can be referenced *like* objects in certain circumstances.

Perhaps this is too strong of an emphasis on the theoretical side of the debate.  From a practical standpoint, I would love to have Groovy&#039;s and Ruby&#039;s syntax for classes.  The problem is that would be one very inconsistent wart in the Scala syntax.  One of the things I love about Scala (and I think everyone does) is the fact that the language design is remarkably consistent.  There are a few wrinkles, but on balance, it&#039;s better designed than any other language I&#039;ve seen.  The reason for this is they avoid things like &quot;special magic convenient syntax for the edge case&quot;.  Scala either uses implicit conversions for the special magic, or it avoids the issue altogether.

&gt; I’m really not sure why everybody
&gt; refers to “Person.class”. Is this
&gt; a Java vs. Scala thing? Is every
&gt; post that mentions Scala and Java
&gt; a Scala vs. Java thing? It wasn’t
&gt; intended as such. I wanted just to
&gt; reference classes in the same way
&gt; I reference objects, by name.

I don&#039;t know about everyone else, but I&#039;m just using Person.class as a convenient example of the &quot;kind&quot; of syntax you are looking for.  Obviously, Person is more concise, but it suffers from the same problems as Person.class while introducing ambiguity into our explanations.

&gt; I’m not sure why this is not possible?

It *is* possible, but that doesn&#039;t mean that it is a desirable language feature.  The one seriously debilitating issue is this syntax introduces ambiguity in the grammar (between class literals and singleton objects).  You obviously foresaw this, suggesting #Person as an alternative.  Practically speaking, there is nothing preventing Scala from having syntax of this form.  What James and I are trying to say is that we don&#039;t think that it would be a good idea for the language as a whole.</description>
		<content:encoded><![CDATA[<p>&gt; I didn’t want to refer to types as objects, but like objects.</p>
<p>I don&#8217;t understand the distinction.  If I were formalizing a language with referable types, it would look exactly the same as a language where types can be referenced *like* objects in certain circumstances.</p>
<p>Perhaps this is too strong of an emphasis on the theoretical side of the debate.  From a practical standpoint, I would love to have Groovy&#8217;s and Ruby&#8217;s syntax for classes.  The problem is that would be one very inconsistent wart in the Scala syntax.  One of the things I love about Scala (and I think everyone does) is the fact that the language design is remarkably consistent.  There are a few wrinkles, but on balance, it&#8217;s better designed than any other language I&#8217;ve seen.  The reason for this is they avoid things like &#8220;special magic convenient syntax for the edge case&#8221;.  Scala either uses implicit conversions for the special magic, or it avoids the issue altogether.</p>
<p>&gt; I’m really not sure why everybody<br />
&gt; refers to “Person.class”. Is this<br />
&gt; a Java vs. Scala thing? Is every<br />
&gt; post that mentions Scala and Java<br />
&gt; a Scala vs. Java thing? It wasn’t<br />
&gt; intended as such. I wanted just to<br />
&gt; reference classes in the same way<br />
&gt; I reference objects, by name.</p>
<p>I don&#8217;t know about everyone else, but I&#8217;m just using Person.class as a convenient example of the &#8220;kind&#8221; of syntax you are looking for.  Obviously, Person is more concise, but it suffers from the same problems as Person.class while introducing ambiguity into our explanations.</p>
<p>&gt; I’m not sure why this is not possible?</p>
<p>It *is* possible, but that doesn&#8217;t mean that it is a desirable language feature.  The one seriously debilitating issue is this syntax introduces ambiguity in the grammar (between class literals and singleton objects).  You obviously foresaw this, suggesting #Person as an alternative.  Practically speaking, there is nothing preventing Scala from having syntax of this form.  What James and I are trying to say is that we don&#8217;t think that it would be a good idea for the language as a whole.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Iry</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206684</link>
		<dc:creator>James Iry</dc:creator>
		<pubDate>Thu, 27 Nov 2008 17:27:31 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206684</guid>
		<description>@Stephan: I’ve read my post again, because I thought I did make a mistake, but I can’t find a statement where I want Person.class in Scala.

post line 1, sentence 2: Currently in Scala you need to write classOf[Person] for the Java Person.class expression. 

Perhaps I misunderstood, but I thought you didn&#039;t like scala&#039;s type function notations compared with Java&#039;s methodish notation.

To explain my post..

class : a construct used by the compiler to specify the detailed representation of runtime objects belonging to a family of types.  List is a class (or maybe trait, I don&#039;t remember) in Scala.

metaobject : a runtime representation of a type or class depending on the system.  In Java, List.class is a metaobject (not a class).  classOf[List[_]] is more or less the equivalent in Scala.  Note that Scala&#039;s type system was built around parametric polymorphism from the beginning, so you can&#039;t just have classOf[List] where as Java was not so you can&#039;t have List[Person].class.  Metaobjects in Java and Scala all have type Class[X] for some X and are instantiations of class Class.  This abuse of the word &quot;class&quot; is a large source of confusion.  Also, Scala will soon have &quot;Manifest&quot;, an alternative form of metaobject.

static type (or just type) : a construct used by the semantic checking phase to verify consistency.  In Scala List[Person] is a type and so is List[_], but List is not and neither is classOf[List[_]].

runtime type : information about an object used for runtime checks of validity of certain operations and for dynamic dispatch.  Due to parametric type erasure, the runtime type system in Java is primitive when compared to its static type system.

Having said all of that, I do now see that your point was more about Groovy and how it can automatically use a metaobject when you put a type in a value location.  Just a misunderstanding on my part, I focused to narrowly on the first two sentences. Anyway, Scala could have done what you say, but there&#039;s a bit of ambiguity 

scala&gt; case class Foo                  
defined class Foo

scala&gt; val f = Foo     

According to the current Scala spec this is already valid and what it does is make f refer to the Foo constructor as a first class function. 

As for my &quot;silly&quot; comment, I didn&#039;t mean you were silly, I meant that your example was clearly targeted as being a silly syntactic construct.  Apologies.</description>
		<content:encoded><![CDATA[<p>@Stephan: I’ve read my post again, because I thought I did make a mistake, but I can’t find a statement where I want Person.class in Scala.</p>
<p>post line 1, sentence 2: Currently in Scala you need to write classOf[Person] for the Java Person.class expression. </p>
<p>Perhaps I misunderstood, but I thought you didn&#8217;t like scala&#8217;s type function notations compared with Java&#8217;s methodish notation.</p>
<p>To explain my post..</p>
<p>class : a construct used by the compiler to specify the detailed representation of runtime objects belonging to a family of types.  List is a class (or maybe trait, I don&#8217;t remember) in Scala.</p>
<p>metaobject : a runtime representation of a type or class depending on the system.  In Java, List.class is a metaobject (not a class).  classOf[List[_]] is more or less the equivalent in Scala.  Note that Scala&#8217;s type system was built around parametric polymorphism from the beginning, so you can&#8217;t just have classOf[List] where as Java was not so you can&#8217;t have List[Person].class.  Metaobjects in Java and Scala all have type Class[X] for some X and are instantiations of class Class.  This abuse of the word &#8220;class&#8221; is a large source of confusion.  Also, Scala will soon have &#8220;Manifest&#8221;, an alternative form of metaobject.</p>
<p>static type (or just type) : a construct used by the semantic checking phase to verify consistency.  In Scala List[Person] is a type and so is List[_], but List is not and neither is classOf[List[_]].</p>
<p>runtime type : information about an object used for runtime checks of validity of certain operations and for dynamic dispatch.  Due to parametric type erasure, the runtime type system in Java is primitive when compared to its static type system.</p>
<p>Having said all of that, I do now see that your point was more about Groovy and how it can automatically use a metaobject when you put a type in a value location.  Just a misunderstanding on my part, I focused to narrowly on the first two sentences. Anyway, Scala could have done what you say, but there&#8217;s a bit of ambiguity </p>
<p>scala&gt; case class Foo<br />
defined class Foo</p>
<p>scala&gt; val f = Foo     </p>
<p>According to the current Scala spec this is already valid and what it does is make f refer to the Foo constructor as a first class function. </p>
<p>As for my &#8220;silly&#8221; comment, I didn&#8217;t mean you were silly, I meant that your example was clearly targeted as being a silly syntactic construct.  Apologies.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206680</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 27 Nov 2008 17:01:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206680</guid>
		<description>Nice hack.

&quot;If you can refer to types as objects, then you have one really weird language.&quot;

I didn&#039;t want to refer to types as objects, but like objects.

&quot;I agree that classOf[Person] is ugly, but from a theoretical and consistency standpoint, it is infinitely superior to Java’s Person.class.&quot;

I&#039;m really not sure why everybody refers to &quot;Person.class&quot;. Is this a Java vs. Scala thing? Is every post that mentions Scala and Java a Scala vs. Java thing? It wasn&#039;t intended as such. I wanted just to reference classes in the same way I reference objects, by name.

James iterated over implementation issues of classOf[] vs. .class, not about accessing objects and classes. 

I&#039;m not sure why this is not possible?</description>
		<content:encoded><![CDATA[<p>Nice hack.</p>
<p>&#8220;If you can refer to types as objects, then you have one really weird language.&#8221;</p>
<p>I didn&#8217;t want to refer to types as objects, but like objects.</p>
<p>&#8220;I agree that classOf[Person] is ugly, but from a theoretical and consistency standpoint, it is infinitely superior to Java’s Person.class.&#8221;</p>
<p>I&#8217;m really not sure why everybody refers to &#8220;Person.class&#8221;. Is this a Java vs. Scala thing? Is every post that mentions Scala and Java a Scala vs. Java thing? It wasn&#8217;t intended as such. I wanted just to reference classes in the same way I reference objects, by name.</p>
<p>James iterated over implementation issues of classOf[] vs. .class, not about accessing objects and classes. </p>
<p>I&#8217;m not sure why this is not possible?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Spiewak</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206676</link>
		<dc:creator>Daniel Spiewak</dc:creator>
		<pubDate>Thu, 27 Nov 2008 16:50:45 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206676</guid>
		<description>If you want to be nasty, you can leverage companion objects + implicit conversion for this:

trait MetaClass {
  def toClass = {
    val name = getClass.getName
    if (name.endsWith(&quot;$&quot;) {
      val cname = name.substring(0, name.length - 1)
      Class.forName(cname)
    } else {
      throw new RuntimeException(&quot;No companion class!&quot;)
    }
  }
}

object MetaClass {
  implicit def metaToClass[A](m: MetaClass): Class[A] = m.toClass
}

// example
trait Service { ... }

object Service extends MetaObject

import MetaClass._
binder.bind(Service)

It&#039;s ugly and unsafe and rather antithetical to the language design, but you can do it.

James pretty much correctly summed up the reasons why classOf[Person] is better than Person.class and *much* better than Person: Person is a *type*, it is not a meta-object.  If you can refer to types as objects, then you have one really weird language.  Depending on what you can do with that type once you&#039;ve got it, such a feature may even make your type system unsound.

I agree that classOf[Person] is ugly, but from a theoretical and consistency standpoint, it is infinitely superior to Java&#039;s Person.class.  Its only three characters extra, I would try to get used to it if I were you.</description>
		<content:encoded><![CDATA[<p>If you want to be nasty, you can leverage companion objects + implicit conversion for this:</p>
<p>trait MetaClass {<br />
  def toClass = {<br />
    val name = getClass.getName<br />
    if (name.endsWith(&#8220;$&#8221;) {<br />
      val cname = name.substring(0, name.length &#8211; 1)<br />
      Class.forName(cname)<br />
    } else {<br />
      throw new RuntimeException(&#8220;No companion class!&#8221;)<br />
    }<br />
  }<br />
}</p>
<p>object MetaClass {<br />
  implicit def metaToClass[A](m: MetaClass): Class[A] = m.toClass<br />
}</p>
<p>// example<br />
trait Service { &#8230; }</p>
<p>object Service extends MetaObject</p>
<p>import MetaClass._<br />
binder.bind(Service)</p>
<p>It&#8217;s ugly and unsafe and rather antithetical to the language design, but you can do it.</p>
<p>James pretty much correctly summed up the reasons why classOf[Person] is better than Person.class and *much* better than Person: Person is a *type*, it is not a meta-object.  If you can refer to types as objects, then you have one really weird language.  Depending on what you can do with that type once you&#8217;ve got it, such a feature may even make your type system unsound.</p>
<p>I agree that classOf[Person] is ugly, but from a theoretical and consistency standpoint, it is infinitely superior to Java&#8217;s Person.class.  Its only three characters extra, I would try to get used to it if I were you.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206606</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 27 Nov 2008 14:42:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206606</guid>
		<description>@pk11: I&#039;ve read my post again, because I thought I did make a mistake, but I can&#039;t find a statement where I want Person.class in Scala.  So perhaps I&#039;m missunderstanding both you and James. Could you help? 

Perhaps you could give a code example of your Pico use to make it clearer for me.

In the post I wished for referencing classes the same way I reference objects, by name. Such as Groovy does it.

&lt;pre&gt;
class MyModule implements Module {
    void configure(Binder binder) {
        binder.bind(Service)
            .to(ServiceImpl)
            .in(Scopes.SINGLETON)
    }
}
&lt;/pre&gt;
http://glaforge.free.fr/weblog/index.php?itemid=208</description>
		<content:encoded><![CDATA[<p>@pk11: I&#8217;ve read my post again, because I thought I did make a mistake, but I can&#8217;t find a statement where I want Person.class in Scala.  So perhaps I&#8217;m missunderstanding both you and James. Could you help? </p>
<p>Perhaps you could give a code example of your Pico use to make it clearer for me.</p>
<p>In the post I wished for referencing classes the same way I reference objects, by name. Such as Groovy does it.</p>
<pre>
class MyModule implements Module {
    void configure(Binder binder) {
        binder.bind(Service)
            .to(ServiceImpl)
            .in(Scopes.SINGLETON)
    }
}
</pre>
<p><a href="http://glaforge.free.fr/weblog/index.php?itemid=208" rel="nofollow">http://glaforge.free.fr/weblog/index.php?itemid=208</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: pk11</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206600</link>
		<dc:creator>pk11</dc:creator>
		<pubDate>Thu, 27 Nov 2008 14:34:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206600</guid>
		<description>hi stephan,

I might be wrong but I think it&#039;s probably possible to create a simple implicit conversion for Object.class-&gt;ClassOf[Object] to get java-like class literals

(btw we use pico container with scala where we mix java and scala components and this setup is working just fine.)</description>
		<content:encoded><![CDATA[<p>hi stephan,</p>
<p>I might be wrong but I think it&#8217;s probably possible to create a simple implicit conversion for Object.class-&gt;ClassOf[Object] to get java-like class literals</p>
<p>(btw we use pico container with scala where we mix java and scala components and this setup is working just fine.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206581</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 27 Nov 2008 14:11:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206581</guid>
		<description>&quot;classOf[Person]&quot;

Shouldn&#039;t this then be called Class[Person]?

&quot;As for your silly &quot;objectOf&quot; example, the symmetrical example would be that in Java you would always have to write&quot;

There would be more to be said in an answer to your comment concerning Person.class, because it seems to me you haven read the post, especially the Groovy part. But this is where this discussion stops, people using &quot;silly&quot; in a discussion are usually not interested in the discussion but interested in being right. And this leads from a community of doing the best to a fanatical we&#039;re right. Thanks for your comment, perhaps it might help other people.</description>
		<content:encoded><![CDATA[<p>&#8220;classOf[Person]&#8221;</p>
<p>Shouldn&#8217;t this then be called Class[Person]?</p>
<p>&#8220;As for your silly &#8220;objectOf&#8221; example, the symmetrical example would be that in Java you would always have to write&#8221;</p>
<p>There would be more to be said in an answer to your comment concerning Person.class, because it seems to me you haven read the post, especially the Groovy part. But this is where this discussion stops, people using &#8220;silly&#8221; in a discussion are usually not interested in the discussion but interested in being right. And this leads from a community of doing the best to a fanatical we&#8217;re right. Thanks for your comment, perhaps it might help other people.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Iry</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206573</link>
		<dc:creator>James Iry</dc:creator>
		<pubDate>Thu, 27 Nov 2008 14:02:35 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206573</guid>
		<description>Stephan, Scala uses square brackets for  what are best thought of as static functions over static types.  

It&#039;s the same notation used in parametric polymorphism (aka generics).  E.g.  you can write

def id[X](x : X) = x
val stringId = id[String] _

Which says take the polymorphic identity function and create an a function object specialized on String.

val people = List[Person]()

Which says take the List class, find a List constructor and specialized it on Person and then call the constructor.

And finally, you can write

classOf[Person] 

Which instantiates the nullary classOf[X] function, which conceptually instantiates a specific classOf for Person and then calls that function.

Thus classOf[List[Person]] is a perfectly natural thing to write in the language.  Special syntax so that you can write List[Person].class would feel unnatural and would not make design sense.  I find this (and many) aspects of Scala&#039;s design aesthetic much cleaner than Java&#039;s.

As for your silly &quot;objectOf&quot; example, the symmetrical example would be that in Java you would always have to write

Person person = department.object.headOf.object

You have no problem writing Person.class in Java now because you&#039;re used to it.  When I first encountered it I was confused because it was treating the type as if it were a metaobject with a class method.  But that wasn&#039;t the case.  I couldn&#039;t do things like Person.newInstance(), I had to write Person.class.newInstance().  Scala&#039;s notation makes it clear that classOf[Person] isn&#039;t a method on a metaobject, but a function on a static type.  What it returns is a metaobject on which you are free to call methods like newInstance.</description>
		<content:encoded><![CDATA[<p>Stephan, Scala uses square brackets for  what are best thought of as static functions over static types.  </p>
<p>It&#8217;s the same notation used in parametric polymorphism (aka generics).  E.g.  you can write</p>
<p>def id[X](x : X) = x<br />
val stringId = id[String] _</p>
<p>Which says take the polymorphic identity function and create an a function object specialized on String.</p>
<p>val people = List[Person]()</p>
<p>Which says take the List class, find a List constructor and specialized it on Person and then call the constructor.</p>
<p>And finally, you can write</p>
<p>classOf[Person] </p>
<p>Which instantiates the nullary classOf[X] function, which conceptually instantiates a specific classOf for Person and then calls that function.</p>
<p>Thus classOf[List[Person]] is a perfectly natural thing to write in the language.  Special syntax so that you can write List[Person].class would feel unnatural and would not make design sense.  I find this (and many) aspects of Scala&#8217;s design aesthetic much cleaner than Java&#8217;s.</p>
<p>As for your silly &#8220;objectOf&#8221; example, the symmetrical example would be that in Java you would always have to write</p>
<p>Person person = department.object.headOf.object</p>
<p>You have no problem writing Person.class in Java now because you&#8217;re used to it.  When I first encountered it I was confused because it was treating the type as if it were a metaobject with a class method.  But that wasn&#8217;t the case.  I couldn&#8217;t do things like Person.newInstance(), I had to write Person.class.newInstance().  Scala&#8217;s notation makes it clear that classOf[Person] isn&#8217;t a method on a metaobject, but a function on a static type.  What it returns is a metaobject on which you are free to call methods like newInstance.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206489</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 27 Nov 2008 10:33:00 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206489</guid>
		<description>Assume one moment referencing objects would be a library feature and you would need to write

var objectOf[person] = objectOf[department] headOf 

instead of 

var person = department headOf

The first one doesn&#039;t look &quot;native&quot;</description>
		<content:encoded><![CDATA[<p>Assume one moment referencing objects would be a library feature and you would need to write</p>
<p>var objectOf[person] = objectOf[department] headOf </p>
<p>instead of </p>
<p>var person = department headOf</p>
<p>The first one doesn&#8217;t look &#8220;native&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206487</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 27 Nov 2008 10:30:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206487</guid>
		<description>@Ricky: No, as I&#039;ve said, I don&#039;t want to. It&#039;s the feel of it:

&quot;@Ricky: From my point of view, classOf[] looks like library support not native support.&quot;

&quot;I refer you to Guy Steele’s talk “Growing a Language” to explain why there should be no difference between library- and language-provided features.&quot;

I refer to objects by their name e.g. &quot;person&quot;, I want to refer to classes by their name, e.g. &quot;Person&quot;.

As I&#039;ve said, perhaps it&#039;s only my perception, but Person.class looks like an language feature and classOf[Person] looks like an library feature (feeling != implementation). Citing Guy Steel there shouldn&#039;t be a difference?

I&#039;ll take a look at the video again though I have the feeling it won&#039;t clear this issue up.</description>
		<content:encoded><![CDATA[<p>@Ricky: No, as I&#8217;ve said, I don&#8217;t want to. It&#8217;s the feel of it:</p>
<p>&#8220;@Ricky: From my point of view, classOf[] looks like library support not native support.&#8221;</p>
<p>&#8220;I refer you to Guy Steele’s talk “Growing a Language” to explain why there should be no difference between library- and language-provided features.&#8221;</p>
<p>I refer to objects by their name e.g. &#8220;person&#8221;, I want to refer to classes by their name, e.g. &#8220;Person&#8221;.</p>
<p>As I&#8217;ve said, perhaps it&#8217;s only my perception, but Person.class looks like an language feature and classOf[Person] looks like an library feature (feeling != implementation). Citing Guy Steel there shouldn&#8217;t be a difference?</p>
<p>I&#8217;ll take a look at the video again though I have the feeling it won&#8217;t clear this issue up.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206483</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Thu, 27 Nov 2008 10:25:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206483</guid>
		<description>Then I&#039;m surprised that you want to differentiate between library- and language-provided features.</description>
		<content:encoded><![CDATA[<p>Then I&#8217;m surprised that you want to differentiate between library- and language-provided features.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206481</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 27 Nov 2008 10:22:42 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206481</guid>
		<description>I know the talk, who doesn&#039;t?</description>
		<content:encoded><![CDATA[<p>I know the talk, who doesn&#8217;t?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206480</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Thu, 27 Nov 2008 10:21:44 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206480</guid>
		<description>classOf is certainly in the library, though it has a &#039;magic&#039; implementation in the compiler, i.e., it compiles down to the same thing as Java&#039;s .class.

I refer you to Guy Steele&#039;s talk &quot;Growing a Language&quot; to explain why there should be no difference between library- and language-provided features.  Bear with it (the talk), I know it&#039;s odd at first.

http://video.google.com/videoplay?docid=-8860158196198824415</description>
		<content:encoded><![CDATA[<p>classOf is certainly in the library, though it has a &#8216;magic&#8217; implementation in the compiler, i.e., it compiles down to the same thing as Java&#8217;s .class.</p>
<p>I refer you to Guy Steele&#8217;s talk &#8220;Growing a Language&#8221; to explain why there should be no difference between library- and language-provided features.  Bear with it (the talk), I know it&#8217;s odd at first.</p>
<p><a href="http://video.google.com/videoplay?docid=-8860158196198824415" rel="nofollow">http://video.google.com/videoplay?docid=-8860158196198824415</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: stephan</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206477</link>
		<dc:creator>stephan</dc:creator>
		<pubDate>Thu, 27 Nov 2008 10:17:39 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206477</guid>
		<description>@Ricky: From my point of view, classOf[] looks like library support not native support. Perhaps we have a different perception here.

And being a different syntax has - for me - nothing to do if the solution is native in the language or looks like a library feature.

[edit] (I guess you&#039;re right it&#039;s native, but it feels like a library feature compared with &lt;code&gt;.class&lt;/code&gt; or using &lt;code&gt;Person&lt;/code&gt; directly, which feels like a language feature, even &lt;code&gt;instanceof&lt;/code&gt; feels more like a language feature than &lt;code&gt;classOf[]&lt;/code&gt; to me.)</description>
		<content:encoded><![CDATA[<p>@Ricky: From my point of view, classOf[] looks like library support not native support. Perhaps we have a different perception here.</p>
<p>And being a different syntax has &#8211; for me &#8211; nothing to do if the solution is native in the language or looks like a library feature.</p>
<p>[edit] (I guess you&#8217;re right it&#8217;s native, but it feels like a library feature compared with <code>.class</code> or using <code>Person</code> directly, which feels like a language feature, even <code>instanceof</code> feels more like a language feature than <code>classOf[]</code> to me.)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ricky Clarkson</title>
		<link>http://codemonkeyism.com/native-type-support-in-scala-wish-for-28/comment-page-1/#comment-206475</link>
		<dc:creator>Ricky Clarkson</dc:creator>
		<pubDate>Thu, 27 Nov 2008 10:09:53 +0000</pubDate>
		<guid isPermaLink="false">http://www.codemonkeyism.com/?p=361#comment-206475</guid>
		<description>That *is* native support.  You&#039;re just asking for extra syntax, which is fair, but different to asking for native support.</description>
		<content:encoded><![CDATA[<p>That *is* native support.  You&#8217;re just asking for extra syntax, which is fair, but different to asking for native support.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk (user agent is rejected)
Database Caching 4/35 queries in 0.043 seconds using disk

Served from: codemonkeyism.com @ 2012-02-10 07:29:13 -->
