comp.lang.ada
 help / color / mirror / Atom feed
From: Duncan Sands <baldrick@free.fr>
To: <comp.lang.ada@ada-france.org>
Subject: Dimensions and fixed point types
Date: Wed, 9 Jun 2004 09:11:39 +0200
Date: 2004-06-09T09:11:39+02:00	[thread overview]
Message-ID: <mailman.77.1086765132.391.comp.lang.ada@ada-france.org> (raw)

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.



             reply	other threads:[~2004-06-09  7:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-09  7:11 Duncan Sands [this message]
2004-06-09  7:47 ` Dimensions and fixed point types 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
replies disabled

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