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-Thread: 103376,a84eaf8fb2470909 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Newsgroups: comp.lang.ada Subject: Re: Ada generics References: <1166710494.869393.108730@a3g2000cwd.googlegroups.com> <17fe4xfogg7p5.1dcyc5nyc2gsl.dlg@40tude.net> <1166805696.291429.239590@48g2000cwx.googlegroups.com> From: Markus E Leypold Organization: N/A Date: Fri, 22 Dec 2006 18:33:11 +0100 Message-ID: User-Agent: Some cool user agent (SCUG) Cancel-Lock: sha1:5FydWhnOB1Jumor0kxdvf2XTtDI= MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii NNTP-Posting-Host: 88.72.224.204 X-Trace: news.arcor-ip.de 1166808573 88.72.224.204 (22 Dec 2006 18:29:33 +0200) X-Complaints-To: abuse@arcor-ip.de Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!t-online.de!keepthis.news.telefonica.de!telefonica.de!news-fra1.dfn.de!newsfeed.arcor-ip.de!news.arcor-ip.de!not-for-mail Xref: g2news2.google.com comp.lang.ada:7993 Date: 2006-12-22T18:33:11+01:00 List-Id: "Hyman Rosen" writes: > In any case, it's never been clear to me why constraints on generic > parameters are considered to be so important by some people. Why not > let templates be instantiated with anything the caller likes? In C++, > if the parameters fail to satisfy some requirement in the template, > then the compilation will fail. If the compilation succeeds, then you > have a working instantiation. It's more likely that a constraint will > prevent an unforeseen but valid usage from working than that it will > catch some kind of error. The same kind of argument could be applied to type systems: | In any case, it's never been clear to me why typing is considered | to be so important by some people ... It's more likely that a type | will prevent an unforeseen but valid usage from working than that | it will catch some kind of error. I think the purpose is not "catching errors" but more likely delivering abstraction. A constraint gives rules how a user of reusable component have to use the component and thus reserve freedom for future implementation changes: "You have to use the compoment like this. Other usages would perhaps work with the present implementation, but we don't want to guarantee for future implementations. We might want to change implementation." That basically is the other side of the contract offered to the component users by the component developers. C++ templates are something like: If it links and if it works then it's OK, if not, bad luck. That is not a contract, just the license to abuse a given implementation. And the license top break any existing implementation. >> 3. Generic object parameters can have any type (in C++ you cannot use >> float, for example) > > Just a note on the float constraint. C++ considers instantiations > identical if their parameters are identical, and introducing floating > point can lead to ambiguities that the language designers chose to > avoid by fiat. It's just the usual floating point issues, e.g., is > 1.0/3.0*3.0 the same as 1.0? On which platforms? Which just goes to show how evil that approach is. Regards -- Markus