milessabin/shapeless — pull request #105 by alexarchambault (2014-06-22 15:24:59+00:00)
Title: Unifysized

The overall goal of this PR is to make more tests of unify pass (see the added lines to the testUnifier method below). It's a rather big PR, some aspects of it may need to be discussed.

The only way I found to have a working implementation of unify is the following: converting the HList to a Sized of the same length having the right Lub, and convert back this Sized to an HList, whose elements are all automatically typed as Lub and whose length is the same as the original HList.

Thus this PR consists in 5 commits (for the sake of the explanation, they can be squashed later):
- the first two make HNil.length compile (used later) and add tests of the length method
- the third one adds a toSized[M] method to HList,
- the fourth one adds a toHList method to Sized,
- and the last one changes the unify implementation so that it uses the two above methods.

The toSized implementation parallels my proposed implementation of toList (see https://github.com/milessabin/shapeless/pull/103). See the changes in ops/hlists.scala and syntax/hlists.scala below, and the added test method testToSized for examples.

The toHList method on Sized is rather straightforward. The required implicits were added to a new object ops.sized. I had to add the Sized itself to the SizedOps case class, as it was needed for the conversion (see the changes in shapeless/sized.scala below). Various tests of it were added.

Finally, I changed the implementation of unify so that it uses these two methods. I removed the current Unify helper object as it wasn't needed anymore.