comp.lang.ada
 help / color / mirror / Atom feed
From: stefan-lucks@see-the.signature
Subject: Re: Incorrect error?
Date: Mon, 18 Jul 2011 14:45:40 +0200
Date: 2011-07-18T14:45:40+02:00	[thread overview]
Message-ID: <Pine.LNX.4.64.1107181400460.1340@medsec1.medien.uni-weimar.de> (raw)
In-Reply-To: <04f4f840-4ea5-407b-8eb7-1f4016ab4e13@d1g2000yqm.googlegroups.com>

[-- Attachment #1: Type: TEXT/PLAIN, Size: 2516 bytes --]

On Mon, 18 Jul 2011, AdaMagica wrote:

> Overloading in this way might be seen as unfortunate.
> 
> > Ada.Numerics.Generic_Real_Arrays actually provides both:
> >
> > � �function "*" (Left, Right : Real_Vector) return Real'Base;
> > � �function "*" (Left, Right : Real_Vector) return Real_Matrix;
> 
> So if you have three vectors, what should A * B * C mean? Even with
> parentheses, it's awkward to read. 

I would always prefer to write such an expression with parenthesis. So 
look at the expression (A * B) * C, where A, B, and C are vectors.  
 -> A * B is either a matrix M or a number N. 
 -> M * C would be a vector. 
 -> N * C would also be a vector. 
 ===> The result type is a vector. 

But wait a minute! There are two different results (either "M * C2 or "N * 
C"), and we don't know which is the correct one. So the compiler should 
reject this.

The issue is that the result type of "A * B" is different from the types 
of A and B. But, as strange as it seems, this is what generations of 
Mathematicians and Engineers seem to have found convenient for their work. 

I am sure, they where able to understand such expressions from context, 
and to provide the context if necessary. Most authors would probably 
prefer to write 

   "M * C with the matrix M being A * B" 

instead of "(A * B) * C" with or without "(", ")". They would thus provide 
the type information, much like any Ada programmer would (have to) do.

> Now image we have a third function
> function "*" (Left, Right : Real_Vector) return Real_Vector;
> 
> BTW: What would such a function return for vectors of less or more
> than 3 dimensions?

It should raise an exception, exactly like 

  function "+" (Left, Right : Real_Vector) return Real_Vector;

from the Ada.Numerics.Generic_Real_Array package. 

I hope the "aspect specifications" from Ada 2012 will allow to specify 
that the vector dimensions fit. In an ideal world (or maybe in Ada 2017), 
the compiler would then statically reject the program if the vector 
dimensions don't fit.

> Why is 'Base the return value? You might instantiate the package with
> a constrained subtype of Float. 'Base is the unconstrained range. Thus
> as long as you stay in the base range, the operators will not
> propagate exceptions.

Ah, that makes sense! Thank you!


-- 
------ Stefan Lucks   --  Bauhaus-University Weimar  --   Germany  ------
               Stefan dot Lucks at uni minus weimar dot de
------  I  love  the  taste  of  Cryptanalysis  in  the  morning!  ------

  parent reply	other threads:[~2011-07-18 12:45 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-18  8:47 Incorrect error? ldries46
2011-07-18  9:45 ` stefan-lucks
2011-07-18 10:10   ` Georg Bauhaus
2011-07-18 11:46     ` ldries46
2011-07-18 10:40   ` AdaMagica
2011-07-18 12:39     ` Dmitry A. Kazakov
2011-07-18 12:45     ` stefan-lucks [this message]
2011-07-18 13:24       ` stefan-lucks
2011-07-18 10:39 ` Nicholas Collin Paul de Glouceſter
2011-07-18 15:58 ` Adam Beneschan
replies disabled

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