型で単位を表す
F#
Haskell
Scala
code:scala
import spire.math._
import spire.implicits._
val length1 = 100.0.withUnitMeter val sum = length1 + length2.inMeter Rust
code:rs
extern crate uom;
use uom::si::f64::*;
use uom::si::length::{meter, centimeter};
fn main() {
let length1 = Length::new::<meter>(100.0);
let length2 = Length::new::<centimeter>(10.0);
let sum = length1 + length2;
}
C++
code:cpp
#include <boost/units/systems/si/length.hpp> #include <boost/units/systems/si/prefixes.hpp> int main() {
using namespace boost::units;
quantity<si::length> length1(100.0 * si::meters);
quantity<si::length> length2(10.0 * si::centimeters);
auto sum = length1 + length2;
}
TypeScript