3 ms·
Interesting - I never thought of CS as being something to help with this. Instead, I’d think of other engineering fields where there is a heavy reliance on corr
by bradlys 6y ago
Interesting - I never thought of CS as being something to help with this. Instead, I’d think of other engineering fields where there is a heavy reliance on correct units and unit conversion. Pound of feathers vs pound of gold , etc...
- scarmig 6y agoF# offers a nifty "unit of measure" language feature to help with that. You might have [<Measure>] type lbFeather [<Measure>] type lbGold [<Measure>] type lbLead let convertGoldToLead ( weight : float<lbGold> ) = 1.0<lbLead> / 1.0<lbGold> * weight // works let barOfGold = 1.0<lbGold> let barOfLead = convertGoldToLead barOfGold // doesn't work let bagOfFeathers = 1.0<lbFeather> let leadDuck = convertGoldToLead bagOfFeathers // Error reported: mismatched units.