3 ms·
I would like a language with real-world data types, with units and automatic unit conversion and checking. Along with Ada-style-ish value limitations (e.g. vari
by lonelygirl15a 5y ago
I would like a language with real-world data types, with units and automatic unit conversion and checking. Along with Ada-style-ish value limitations (e.g. variable must be positive, or between 0 and 100, etc.)
> length i = 12 inches
> length h = 1 foot
> i * h
area 1 square_foot
> square_inches(ih)
area 144 square_inches
> hours(ih)
error: type mismatch
Time and money, as well (currency conversion not required)
- andrepd 5y agoYou can already implement this in any language with strong typing, like C++ or Rust or OCaml or Haskell. I guess the syntax might be more verbose, so you would have to write inches(12) rather than 12 inches.
- TheMonarchist 5y agoC++ has user defined literals, so you could write 12_inch.
- Jeff_Brown 5y agoThe formal term for the Ada-ish constraints on acceptable values is dependent types.
- Jeff_Brown 5y agoWait no, it's close but not as strong as dependent types. I was thinking of Agda.