From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,a59300e1cca1082c X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-09-21 10:13:28 PST Path: archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!news.tele.dk!small.news.tele.dk!194.213.69.151!news.algonet.se!algonet!newsfeed1.uni2.dk!news.net.uni-c.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: Parametrically polymorphic operations (Was: Safe C++) Date: Fri, 21 Sep 2001 19:13:27 +0200 Organization: Centre for Chaos and Turbulence Studies, Niels Bohr Institute Message-ID: <3BAB7537.BC7ED73D@nbi.dk> References: <3BA7A45D.186EE27A@adaworks.com> <20010919072904.O10277-100000@shell5.ba.best.com> <20010919102107.L4954-100000@shell5.ba.best.com> <9ob2u6$2r4l$1@msunews.cl.msu.edu> <3BA9D515.1E6C7A49@nbi.dk> <3BAB65EE.210F4F77@sparc01.ftw.rsc.raytheon.com> NNTP-Posting-Host: alf.nbi.dk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: news.net.uni-c.dk 1001092408 37986 130.225.212.55 (21 Sep 2001 17:13:28 GMT) X-Complaints-To: usenet@news.net.uni-c.dk NNTP-Posting-Date: Fri, 21 Sep 2001 17:13:28 +0000 (UTC) X-Mailer: Mozilla 4.78 [en] (X11; U; OSF1 V4.0 alpha) X-Accept-Language: fo,da,no,sv,is,de,fr,en Xref: archiver1.google.com comp.lang.ada:13238 Date: 2001-09-21T19:13:27+02:00 List-Id: Wes: > Jacob Sparre Andersen wrote: > > safe types, I have certainly wanted something very similar > > to parametrically polymorphic functions. It would make it > > possible to have more extensive compile time checks, than > > what is possible with Ada as it is defined today. > > > > An example: > > > > type Matrix (Left, Right : Positive) is private; Nobody seems to have noticed, but the type should of course have been declared as: type Matrix (Width, Height : Positive) is private; > > > > function "*" (Left : in Matrix; > > Right : in Matrix (Height => Left.Width)) > > return Matrix (Width => Right.Width, > > Height => Left.Height); > > Where are you going to put the result? For example in: Result : Matrix (Width => 4, Height => 4); > If the implementation is reasonable, constraint_error > will be raised when the constraints on the left side don't > the constraints on the result. The implementation of my favourite Ada compiler or the implementation of function "*"? The problem is that the constaints on the result can not be expressed in the specification of "*". You have to put them in the implementation of "*". GNAT may not be a reasonable implementation of an Ada compiler, but it is the one I use most of the time, and I have not been able to get it to complain about mismatches in the dimensions of matrices, when doing matrix multiplications. I would appreciate it, if you could explain us how to write a matrix multiplication function, which allows some of the existing Ada compilers to complain about mismatches in matrix dimensions at compile time. > And if the constraints are static on both, many compilers > will detect it at compile time. Would you care to mention one or two examples? Jacob -- ACRONYM: A Contrived Reduction Of Nomenclature Yielding Mnemonics