stan icon indicating copy to clipboard operation
stan copied to clipboard

Advise to use newtypes in fields of same type

Open vrom911 opened this issue 5 years ago • 1 comments
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}

vrom911 avatar May 30 '20 19:05 vrom911

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.

chshersh avatar Jun 11 '20 14:06 chshersh