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 09:18:46 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news.tele.dk!small.news.tele.dk!130.133.1.3!fu-berlin.de!uni-berlin.de!b8688.pppool.DE!not-for-mail From: dmitry@elros.cbb-automation.de (Dmitry A. Kazakov) Newsgroups: comp.lang.ada Subject: Re: Parametrically polymorphic operations (Was: Safe C++) Date: Thu, 20 Sep 2001 16:22:17 GMT Message-ID: <3baa13ac.4589834@news.cis.dfn.de> 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> NNTP-Posting-Host: b8688.pppool.de (213.7.134.136) X-Trace: fu-berlin.de 1001002724 13297833 213.7.134.136 (16 [77047]) X-Newsreader: Forte Free Agent 1.21/32.243 Xref: archiver1.google.com comp.lang.ada:13219 Date: 2001-09-20T16:22:17+00:00 List-Id: On Thu, 20 Sep 2001 13:37:57 +0200, 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) > >This would tell the compiler a few things, which would allow >it to >flag type mismatches already at compile time. > >The current Ada specification forces us to move these checks >into the body of the functions and procedures. It is more than that. Same problem appears with implementation of measurement units [and many other cases]. The actual problem is that a type has some parameters [better to call them discriminants] that are statically known. These parameters are involved in some expressions with are also static. One should somehow separate these expressions from the implementation of the subroutine body and force them evaluated at compile time. The question is how? (:-)) Then I would argue that it is not parametric polymorphism, because there is no need to provide parameters for the body. There is also no need to have distinct types for matrices of different size [or for each measurement unit etc]. One need to only "distill" the static part from the body. Regards, Dmitry Kazakov