comp.lang.ada
 help / color / mirror / Atom feed
* Dimensions and fixed point types
@ 2004-06-09  7:11 Duncan Sands
  2004-06-09  7:47 ` Martin Dowie
  2004-06-11  7:26 ` Hyman Rosen
  0 siblings, 2 replies; 10+ messages in thread
From: Duncan Sands @ 2004-06-09  7:11 UTC (permalink / raw)
  To: comp.lang.ada

Fixed point types have a remarkable property:
you can multiply any two of them to get a third.
You can multiply apples and oranges and get
bananas.  This goes against type safety.

Suppose I have several fixed point types, for
example

type Price is delta 0.01 digits ...;
type Volume is delta 1.0 digits ...;
type Value is delta 0.01 digits ...;

Then all possible multiplications are legal.  By
declaring some multiplications abstract, I can
remove unwanted operations, and just keep the
ones I want, for example Price * Volume = Value.
(This is already a lot of operations to remove!).

However if somewhere else I define

type Oranges is delta ... digits ...;

then I automagically get a whole bunch of new
operations (Orange * Value = Price etc) that I
don't want.  To be safe I'd need to remove them
all too - it is never ending.  This makes fixed point
types almost useless in a dimensions system, or
whenever you want to catch incorrect operations
based on type.

Maybe there is a trick I am missing though.  Can
anyone see a way to use fixed point types safely
in a setting where multiplying objects of the wrong
type would be fatal?

Also, why were things done this way?  It seems to
me that a much better approach would be to say
that multiplication between different fixed point types
is NOT automatically defined, but can be obtained
by writing something like this:

function "*" (Left : Apples; Right : Oranges) return Banana;
pragma Import (Intrinsic, "*");

Thanks for any comments,

Duncan.



^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-06-12  3:40 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-09  7:11 Dimensions and fixed point types Duncan Sands
2004-06-09  7:47 ` Martin Dowie
2004-06-09 17:04   ` Robert I. Eachus
2004-06-11  7:16     ` Duncan Sands
2004-06-11  7:12   ` Duncan Sands
2004-06-11  7:26 ` Hyman Rosen
2004-06-11  7:46   ` Duncan Sands
2004-06-11 17:47     ` Hyman Rosen
2004-06-11 19:10       ` Duncan Sands
2004-06-12  3:40         ` Robert I. Eachus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox