Jason Zaugg | 11 Dec 08:18 2011

Implicit Scope: Type Params vs Type Members

I've been experimenting with using type members, rather than type parameters, through the Scalaz type class hierarchy. Together with dependent method types, this can afford better type inference. Compare the usage of `Functor#compose` in this gist [1] against similar usages [2] when using type parameters.

One small problem with this encoding, is that the implicit scope no longer includes the classified types.

  trait TC_ { type F }
  type TC[G] = TC_ { type F = G }

  trait Data
  object Data {
    implicit val instance = new TC { type F = Data }

  implicitly[TC[Data]] // fail, need to import Data._

In the interest of making type parameters and type members more easily interchangable, would it make sense to include the RHS of type members to the
parts of a type?


[1] https://gist.github.com/1458981
[2] https://github.com/scalaz/scalaz/blob/scalaz-seven/example/src/main/scala/scalaz/example/WordCount.scala#L35