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-20 08:49:21 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!feed.textport.net!out.nntp.be!propagator-SanJose!news-in!easynews!sjc-peer.news.verio.net!news.verio.net!sea-read.news.verio.net.POSTED!not-for-mail Newsgroups: comp.lang.ada From: Brian Rogoff Subject: Re: Parametrically polymorphic operations (Was: Safe C++) In-Reply-To: <3BA9D515.1E6C7A49@nbi.dk> Message-ID: <20010920083828.Y7505-100000@shell5.ba.best.com> 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> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Date: Thu, 20 Sep 2001 15:49:19 GMT NNTP-Posting-Host: 206.184.139.136 X-Complaints-To: abuse@verio.net X-Trace: sea-read.news.verio.net 1001000959 206.184.139.136 (Thu, 20 Sep 2001 15:49:19 GMT) NNTP-Posting-Date: Thu, 20 Sep 2001 15:49:19 GMT Organization: Verio Xref: archiver1.google.com comp.lang.ada:13216 Date: 2001-09-20T15:49:19+00:00 List-Id: On Thu, 20 Sep 2001, Jacob Sparre Andersen wrote: > Chad: > > "Brian Rogoff" wrote in message > [...] > > > Parametrically polymorphic functions > > > I'll have to trust you or these three since I have never encountered a > > situation where I was ever wishing for such functionality. > > While working on libraries for matrix operations and unit > 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; > > function "*" (Left : in Matrix; > Right : in Matrix (Height => Left.Width)) > return Matrix (Width => Right.Width, > Height => Left.Height); > > (I hope the intention is clear although the syntax isn't > defined) That you want to multiply an M x N and a N x K matrix and have it type check at compile time and produce an M X K matrix? I only very recently learned how to do this in ML (look for a posting by Matthias Blume on comp.lang.ml replying to one of mine in the last year) and I have to say it was a bit surprising. I guess it shouldn't have been; one of the ideas in the technique is the same as used to create a type safe printf library (printer combinators) and is just generally useful. I don't know if it's really appropriate to post it here since it's a fair bit (~200 lines) of non-Ada code :-). > This would tell the compiler a few things, which would allow > it to flag type mismatches already at compile time. With the technique I mention, there is no question of the compiler being "allowed" to flag the mismatch. The dimensions are moved into the type system so the type checker rejects it! Just like with the printer combinators. -- Brian