3 ms·
You are right that `Angle` is the wrong name for a newtype but wrong that this is not a job for types. > Wrapping something in a type doesn't magically change
by morelisp 4y ago
You are right that `Angle` is the wrong name for a newtype but wrong that this is not a job for types.
> Wrapping something in a type doesn't magically change its value.
Most formal definitions of value disagree, e.g. from Stepanov & McJones:
A value type is a correspondence between a species (abstract or concrete)
and a set of datums. A datum corresponding to a particular entity is called
a representation of the entity; the entity is called the interpretation of the
datum. We refer to a datum together with its interpretation as a value. In this case the species is abstract, rotational measurement - and the interpretation is the unit. 2pi radians, 360 degrees, and 1 turn all correspond to the same abstract entity; radians, degrees, and turns are types.
But you can also find the mistake just based on your own comment, where you've taken an unjustified leap from variable to value:
> Types are just labels applied to variables... Wrapping something in a type doesn't magically change its value.
Types are labels applied to variables, specifically in order to produce a particular value from the contents of some memory region (what Stepanov & McJones call "datum"). If changing types didn't change values, types would be near-useless (cf, as a concrete example, C's near-useless type system).