typeTag on higher-kinded types?

332 views
Skip to first unread message

Paolo Giarrusso

unread,
Jul 20, 2012, 10:32:26 AM7/20/12
to scala-l...@googlegroups.com
Hi all, I thought I had read that TypeTags can represent all types, but I seem to have found an exception for -M5:

scala> trait Foo[C[_]]
defined trait Foo

scala> import scala.reflect.runtime.{universe => u}
import scala.reflect.runtime.{universe=>u}

scala> u.typeTag[Foo[({type l[X] = (Int, X)})#l]]
<console>:27: error: No TypeTag available for Foo[[X](Int, X)]
              u.typeTag[Foo[({type l[X] = (Int, X)})#l]]

I feel betrayed by the ScalaDoc! And it seems this is going to be a problem.

The same problem seems to apply to local declarations within methods, such as `type QueryAnd[+T] = (Int, T)`. The same declaration as a class member is fine.

While at this, `typeTag` does not accept type constructors, only proper types, which seems confusing. Have type constructors become second-class now? Should I always use dummy higher-kinded types* (like `Foo` above) to pass them around?

* I minded Adriaan's oft-repeated warning and used the term correctly, at least I think!

Eugene Burmako

unread,
Jul 20, 2012, 10:37:33 AM7/20/12
to scala-l...@googlegroups.com
If you turn -Xlog-implicits on, you'll see the following message:

cannot reify TypeTag having unresolved type parameter X

typeTag[Foo[({type l[X] = (Int, X)})#l]]

I'll look into whether or not this error message is correct. In the meanwhile implicitly[u.AbsTypeTag[...]] works.

Paul Phillips

unread,
Jul 20, 2012, 10:38:00 AM7/20/12
to scala-l...@googlegroups.com


On Fri, Jul 20, 2012 at 7:32 AM, Paolo Giarrusso <p.gia...@gmail.com> wrote:
scala> u.typeTag[Foo[({type l[X] = (Int, X)})#l]]
<console>:27: error: No TypeTag available for Foo[[X](Int, X)]
              u.typeTag[Foo[({type l[X] = (Int, X)})#l]]

scala> u.typeTag[Foo[CC] forSome { type CC[_] }]
warning: there were 1 feature warnings; re-run with -feature for details
res2: reflect.runtime.universe.TypeTag[Foo[_[_] <: Any]] = TypeTag[Foo[_[_] <: Any]]

Adriaan Moors

unread,
Nov 5, 2012, 7:29:36 PM11/5/12
to scala-l...@googlegroups.com

While at this, `typeTag` does not accept type constructors, only proper types, which seems confusing. Have type constructors become second-class now?
type constructors are still first class, but we don't have kind polymorphism:
when you're expecting (abstracting over) a proper type, you will only get a proper type, and conversely for other kinds 

we can't abstract over kinds and thus typeTag has to pick a concrete one (it picked the kind of proper types), which means you can only pass it a proper type
 
Should I always use dummy higher-kinded types* (like `Foo` above) to pass them around? 

* I minded Adriaan's oft-repeated warning and used the term correctly, at least I think!
yep: Foo is a type that abstracts over a type that abstracts over a type --> that's higher-order  

adriaan

Paolo Giarrusso

unread,
Nov 8, 2012, 6:27:42 PM11/8/12
to scala-l...@googlegroups.com
On Mon, Nov 5, 2012 at 4:29 PM, Adriaan Moors
<adriaa...@typesafe.com> wrote:
>
>> While at this, `typeTag` does not accept type constructors, only proper
>> types, which seems confusing. Have type constructors become second-class
>> now?
>
> type constructors are still first class, but we don't have kind
> polymorphism:
> when you're expecting (abstracting over) a proper type, you will only get a
> proper type, and conversely for other kinds
>
> we can't abstract over kinds and thus typeTag has to pick a concrete one (it
> picked the kind of proper types), which means you can only pass it a proper
> type

I guess I'm thinking of typeTag1...typeTag10, while being annoyed at
the lack of type currying by default (as in Haskell).

Since you're codesigning Scala 3, it would be nice to support type
currying: at the value level that would have performance and/or
syntactic implications (Haskell has specific compile-time and runtime
support to make partial applications cheap enough), but at least the
performance problems don't carry over to the type-level (if the
concept of type parameter is there to stay, as it looks). What I don't
understand yet is if you can write/encode higher-kinded types in some
way in DOT, as I'd guess.

Cheers,
Paolo
--
Paolo G. Giarrusso - Ph.D. Student, Philipps-University Marburg
http://www.informatik.uni-marburg.de/~pgiarrusso/

Adriaan Moors

unread,
Nov 9, 2012, 4:51:49 PM11/9/12
to scala-l...@googlegroups.com


On Thu, Nov 8, 2012 at 3:27 PM, Paolo Giarrusso <p.gia...@gmail.com> wrote:
What I don't understand yet is if you can write/encode higher-kinded types in some way in DOT, as I'd guess.
definitely -- http://adriaanm.github.com/files/scalina-final.pdf
Reply all
Reply to author
Forward
0 new messages