hobwekiva / newtypes

MIT License
115 stars 4 forks source link

Comparison with Shapeless's `tag`? #4

Open acjay opened 7 years ago

acjay commented 7 years ago

Not knowing this project existed, I created my own project that's very similar: https://github.com/acjay/taggy. A friend clued me into Newtypes and looking into it, I realized that Shapeless's tag has yet another implementation of this pattern:

object tag {
  def apply[U] = new Tagger[U]

  trait Tagged[U]
  type @@[+T, U] = T with Tagged[U]

  class Tagger[U] {
    def apply[T](t : T) : T @@ U = t.asInstanceOf[T @@ U]
  }
}

It seems most similar to the translucent option in this package, but I'm wondering if there are any significant differences? Would it be a good idea to an implementation based on this approach in Newtypes too?

hobwekiva commented 6 years ago

I recently made some major modifications to newtypes. The current encoding of translucent types is almost identical to @@, the only difference is that @translucent type A = Int defines A as an abstract type. The only case I know of where that might be important is @translucent type Void = Nothing, which does not break implicit resolution (Nothing itself does).

hobwekiva commented 6 years ago

See https://github.com/scalaz/scalaz/pull/1450#issuecomment-332288733 for an explanation of the current encoding.