Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any languages that allow units?

Tags:

When writing the following today in C#

DateTime.Now.AddYears(-60) 

I wondered whether there are any languages that allow a more natural syntax with units:

DateTime.Now - 60years 

Does anyone know of any? Specifically, I'm interested in the presence of unit operators(?) that turn "60years" into e.g. "TimeSpan.FromYears(60)". It'd also be neat to be able to define your own unit operators, similar to how you can write conversion operators in C#

(Yes, I know TimeSpan doesn't cater for years -- it's an example.)

like image 624
bruceboughton Avatar asked Aug 21 '09 13:08

bruceboughton


People also ask

What are the 3 types of programming language?

There are three types of programming languages: machine language, assembly language, and high-level language. Machine language is easier for the computer to understand but harder for the programmer to understand.

What coding language is unity?

The language that's used in Unity is called C# (pronounced C-sharp). All the languages that Unity operates with are object-oriented scripting languages. Like any language, scripting languages have syntax, or parts of speech, and the primary parts are called variables, functions, and classes.

Can you program in any language?

In addition to these four widely available, multilingual programming languages, there are several dozen, maybe a hundred or so, programming languages that are available in a language or two other than English, such as Qalb (Arabic), Chinese Python, farsinet (Persian), Hindawi Programming System (Bengali, Gujarati, and ...


1 Answers

F# has units of measure. Some examples from

http://blogs.msdn.com/andrewkennedy/archive/2008/08/20/units-of-measure-in-f-part-one-introducing-units.aspx

alt text

alt text

like image 74
Scott Weinstein Avatar answered Oct 05 '22 23:10

Scott Weinstein