Newtype support

After a slight disappointment with opaque types for encoding newtypes, and now with macro annotations possibly on the horizon, it doesn’t seem like either of them will give me what I really want.
The problem in my opinion comes from the inability of combining the solutions with the new typeclass derivation feature.

I really want to be able to write something close to:

newtype PersonId from UUID deriving Equals, Show, Codec

I would also be happy if the macro annotations could observe and handle the deriving clauses, e.g.

@newtype case class PersonId(value:UUID) deriving Equals, Show, Codec

Here we’re naming the underlying value which is unfortunate, but on the upside there’s more freedom to create the implementation as a library. Maybe this would be preferable in the short run as it allows experimentation without changing the language. But this requires macro annotations to work with typeclass derivation.

2 Likes

There was a similar discussion here Pre-SIP derives clauses for opaque types (when macro annotations were not on the horizon yet however)

2 Likes

Yeah, I think the macro annotations changes things, especially since that’s how the scala 2 library was implemented