Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

F# 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.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: