Re:Type all the things
by greydius on Tuesday February 02, 2016 @11:36AM
(#11020458)
Haskell has newtype for this purpose, with the benefit that the compiler removes the added overhead of the additional data type.
[ Parent
| on HN ]
Re:Type all the things
by wickedshimmy on Tuesday February 02, 2016 @12:00PM
(#11020640)
Value classes serve this purpose in Scala: `case class Id(id: Long) extends AnyVal` will have long-typed values at runtime (*mostly).
Is *mostly even true?
Given the list of restrictions here: http://docs.scala-lang.org/overviews/core/value-classes.html
It seems to me that you'd have to be fairly careful to have any confidence your not instantiating classes for them.
Do you know if there are any compiler flags or other way to know if your value classes are working as expected?