milessabin/shapeless — pull request #57 by larsrh (2013-10-23 15:15:07+00:00)
Title: Better hygiene by using `Type` instead of `TypeTree`

## The Problem

The macro which derives type classes produces trees with not-fully-qualified names.

## Previously

(using typelevel/shapeless-contrib@b29840aaef4b75b510ee39f4cde828bfac81a351 against milessabin/shapeless@a269547)

```scala
$ sbt scalaz/console
scala> import shapeless.contrib.scalaz._
import shapeless.contrib.scalaz._

scala> shapeless.contrib.scalaz.deriveOrder[(Int, String)]
performing macro expansion shapeless.contrib.scalaz.`package`.deriveOrder[(Int, String)] at source-,line-8,offset=126
{
object $4$ extends AnyRef {
def () = {
super.();
()
};
def $1$(param1: (Int, String)): ::[Int, ::[String, shapeless.HNil]] = param1 match {
case Tuple2((pat1 @ _), (pat2 @ _)) => ::(pat1, ::(pat2, HNil))
};
def $2$(param2: ::[Int, ::[String, shapeless.HNil]]): (Int, String) = param2 match {
case ::((pat3 @ _), ::((pat4 @ _), _)) => Tuple2(pat3, pat4)
};
lazy val inst2: ProductTypeClass[scalaz.Order] = Predef.implicitly[ProductTypeClass[scalaz.Order]];
lazy val inst3: Order[Int] = Predef.implicitly[Order[Int]];
lazy val inst4: Order[String] = Predef.implicitly[Order[String]];
lazy val inst1: Order[::[Int, ::[String, shapeless.HNil]]] = inst2.product(inst3, inst2.product(inst4, inst2.emptyProduct));
lazy val $3$: Order[(Int, String)] = inst2.project(inst1, $1$, $2$)
};
$4$.$3$
}
:8: error: not found: type ProductTypeClass
shapeless.contrib.scalaz.deriveOrder[(Int, String)]
^
```

## Description of the fix

I replaced almost all occurences of `AppliedTypeTree` by `appliedType`, and instead of wrapping `Type`s into `TypeTree`s early, I do it as late as possible.

Question to @xeno-by: Was I misusing the API?

## Now

With the same invocation:

```scala
{
object $4$ extends AnyRef {
def () = {
super.();
()
};
def $1$(param1: (Int, String)): shapeless.::[Int,shapeless.::[String,shapeless.HNil]] = param1 match {
case Tuple2((pat1 @ _), (pat2 @ _)) => ::(pat1, ::(pat2, HNil))
};
def $2$(param2: shapeless.::[Int,shapeless.::[String,shapeless.HNil]]): (Int, String) = param2 match {
case ::((pat3 @ _), ::((pat4 @ _), _)) => Tuple2(pat3, pat4)
};
lazy val inst2: shapeless.ProductTypeClass[scalaz.Order] = Predef.implicitly[shapeless.ProductTypeClass[scalaz.Order]];
lazy val inst3: scalaz.Order[Int] = Predef.implicitly[scalaz.Order[Int]];
lazy val inst4: scalaz.Order[String] = Predef.implicitly[scalaz.Order[String]];
lazy val inst1: scalaz.Order[shapeless.::[Int,shapeless.::[String,shapeless.HNil]]] = inst2.product(inst3, inst2.product(inst4, inst2.emptyProduct));
lazy val $3$: scalaz.Order[(Int, String)] = inst2.project(inst1, $1$, $2$)
};
$4$.$3$
}
```