comp.lang.ada
 help / color / mirror / Atom feed
From: Martin <martin.dowie@btopenworld.com>
Subject: Re: Question on types conversions - operations
Date: Sat, 13 Jun 2009 10:24:22 -0700 (PDT)
Date: 2009-06-13T10:24:22-07:00	[thread overview]
Message-ID: <eeffd925-e397-45f1-9fb1-bb3366ea4c48@d19g2000prh.googlegroups.com> (raw)
In-Reply-To: b2e347bf-e147-4338-ba18-8cfeef9cea8f@d25g2000prn.googlegroups.com

On Jun 13, 5:59 pm, sjw <simon.j.wri...@mac.com> wrote:
> On Jun 13, 4:51 pm, Olivier Scalbert <olivier.scalb...@algosyn.com>
> wrote:
>
>
>
> > I have the following three types:
> >      type Length is new Float;
> >      type Time   is new Float;
> >      type Speed  is new Float;
>
> > Suppose I need to compute a speed given a length and a time.
>
> >      L: Length := 100.0;
> >      T: Time   :=  10.0;
> >      S: Speed;
>
> > How to do that ?
>
> > With S := Speed(Float(L) / Float(T)) ? Mmmm ... not nice.
>
> > With S := Speed(L / Length(T)), I am also not satisfy as I convert a
> > time in Length ...
>
> You could declare functions such as "*" (s : speed; t : time) return
> length and of course "*" (t : time; s : speed) return length.
>
> Inside, you could use
>   return length (float (s) * float (t));
>
> You could use speed'base, time'base but then what if one is
> long_float?
>
> It's always seemed a lot of work for very little gain to me, I've
> declared them as subtypes rather than types and left checking for the
> right answer to unit test. But then, my world is all about logic and
> there are far more enumerations than reals, and very few calculations.
> Also, we tend to have coordinates (x, y) or (r, theta) so it's a lot
> more useful to define "*", "+" etc.

It would be brilliant if units checking could be built into the
standard language...

Cheers
-- Martin



  reply	other threads:[~2009-06-13 17:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-13 15:51 Question on types conversions - operations Olivier Scalbert
2009-06-13 16:13 ` Robert Matthews
2009-06-13 16:55 ` anon
2009-06-13 16:58 ` Dmitry A. Kazakov
2009-06-13 16:59 ` sjw
2009-06-13 17:24   ` Martin [this message]
2009-06-13 19:35     ` sjw
2009-06-14  8:22     ` sjw
2009-06-15  8:40   ` Jean-Pierre Rosen
2009-06-15  9:30     ` Olivier Scalbert
2009-06-15  9:51       ` stefan-lucks
2009-06-15 10:33     ` AdaMagica
2009-06-15 19:37     ` sjw
2009-06-13 19:56 ` Jeffrey R. Carter
2009-06-14 15:55   ` Robert A Duff
2009-06-15  8:52 ` AdaMagica
replies disabled

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