stan
stan copied to clipboard
Advise to use newtypes in fields of same type
trafficstars
Advice to use newtypes in data types with multiple fields with the same type:
data Params = Params
{ height :: !Double -- ^ in cmeters
, weight :: !Double -- ^ in kgs
}
replace with
data Params = Params
{ height :: !Cm
, weight :: !Kg
}
newtype Cm = {unCm :: Double}
newtype Kg = {unKg :: Double}
We discussed that this is not always desirable to have this feature enabled by default. So it will be an opt-in feature which you may want to enable everywhere or in some specific places.