In Haskell we can declare newtypes to reduce dynamic memory allocations and create type-safe APIs.
newtype Username String = Username String
deriving (Eq, Ord)
newtype works only with data types which have single constructor with single argument. Is there something similar to newtype in Scala?
Example:
case class Username(username: String)
for username we could've write something like this in Scala:
newtype Username(username: String)
The equivalent to Haskell's
newtypeare Opaque Type Aliases in Scala 3:It's basically a
typealias … but opaque. Just like it says on the cover.