Skip to content

Instantly share code, notes, and snippets.

@jacobp100
Created November 1, 2019 20:24
Show Gist options
  • Save jacobp100/0f449cd3d910e69ef5ea6120a6f17838 to your computer and use it in GitHub Desktop.
Save jacobp100/0f449cd3d910e69ef5ea6120a6f17838 to your computer and use it in GitHub Desktop.
type length = [ | `Meter | `Inch];
type time = [ | `Second | `Minute | `Hour];
type temperatureLinear = [ | `Kelvin];
type temperatureNonLinear = [ | `Celsius];
type unitLinear = [ length | time | temperatureLinear];
type anyUnit = [ unitLinear | temperatureNonLinear];
let siScale = (unit: unitLinear) =>
switch (unit) {
| `Meter => 1.
| `Inch => 0.0254
| `Second => 1.
| `Minute => 60.
| `Hour => 3600.
| `Kelvin => 1.
};
let toSi = (value, unit: anyUnit) =>
switch (unit) {
| #unitLinear as linearUnit => value *. siScale(linearUnit)
| `Celsius => value +. 273.15
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment