I have a bunch of coordinate systems that I have to use in my personal project. It would benefit me if I could somehow store a meters type within a kilometer type.
A summary of what I think that I am aiming for here is that if something is 8km,500m,070cm,003mm on the x axis, then I wouldn’t have to store that as 8.500_703 inside type Kilometer is delta 10.0**(-6) range -10.0 .. 10.0; but could instead have it stored as a cascade of all relevant types, with everything being put into the largest type that it can go in. I think perhaps this is achievable with additional subprograms, but I really feel as if I could (mis)use the type system in this way.
I was trying weird things that weren’t legal such as:
type Custom_Kilometers is range -10 .. 10;
subtype Custom_Meters is Custom_Kilometers range 1 .. 1 delta 10.0**(3);
I think the second line in the example shows what I am trying to do. To have a parent type, and then add more detail. I understand using the delta like this is wrong, but since it adds decimals I am trying to show my intent in illegal code.
-10 .. 10 km -> 1 .. 1 km -> 1000m .. 1000m
If I pass 1000m into a meters type I would like it to convert to 1km. Wishful thinking I guess.
-- I know this doesn't work, but I am trying to show my intent,
-- as I cannot seem to describe my problem well otherwise.
Some_Weird_Example_Name : Collapsing_Distance_Type := ( km => 2,
m => 4500,
cm => 3,
mm => 5 );
-- Example internal memory representation would be 6km500m3cm5mm etc...
-- the meters for example would left as 500, and the 4k meters into 4km.
I’m not asking anyone to do the work for me. I just need to know if something like I am asking is even possible. It feels like such a weird thing that I am trying to do here, but it’s what I’m after. Is this a strategy for distance storage, is there an alternative, or am I chasing my tail again?