jmeaster30 / ocean

A C-like programming language (get it like sea-like like an ocean lol)
GNU General Public License v3.0
0 stars 0 forks source link

Add an annotation for "units" #104

Open jmeaster30 opened 5 months ago

jmeaster30 commented 5 months ago

Add an annotation for units that goes on function parameters or variable declarations.

This would let the compiler emit a warning/error for mismatched units

Not sure if this needs to be a language feature or if it can be implemented in the standard library.

jmeaster30 commented 4 months ago

It would be cool to do:

function add3centimeters(@unit(cm) num: f64) -> (@unit(cm) result: f64 = num + 3cm);

let a = 10m;
let total = a.add3centimeters(); # this will throw an error saying "Parameter must have units as 'cm' but got a unit of 'm'."

Which makes me think of a couple things that are needed: