I know the = operator can't be overloaded, but there must be a way to do what I want here:
I'm just creating classes to represent quantitative units, since I'm doing a bit of physics. Apparently I can't just inherit from a primitive, but I want my classes to behave exactly like primitives -- I just want them typed differently.
So I'd be able to go,
Velocity ms = 0;
ms = 17.4;
ms += 9.8;
etc.
I'm not sure how to do this. I figured I'd just write some classes like so:
class Power
{
private Double Value { get; set; }
//operator overloads for +, -, /, *, =, etc
}
But apparently I can't overload the assignment operator. Is there any way I can get this behavior?
units of measurefeature of F# ? it knows standard (ISO) units like M, KG and M/S, and it can calculate with units too.[<Measure>] type m; [<Measure>] type sand can then use things likelet a = 9.8<m> / 4.3<s>which yieldsval a : float<m/s> = 2.279069767Microsoft.FSharp.Math.SI. See: blogs.msdn.com/b/andrewkennedy/archive/2008/09/02/…