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,5aa1f17e1cbe0afb X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!peer1.news.newnet.co.uk!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!diphi.demon.co.uk!jpt From: JP Thornley Newsgroups: comp.lang.ada Subject: Re: SPARK and static unit checking? Date: Sun, 13 Apr 2008 20:39:34 +0100 Message-ID: References: NNTP-Posting-Host: diphi.demon.co.uk Mime-Version: 1.0 Content-Type: text/plain;charset=us-ascii;format=flowed X-Trace: news.demon.co.uk 1208115699 11420 80.177.171.182 (13 Apr 2008 19:41:39 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Sun, 13 Apr 2008 19:41:39 +0000 (UTC) User-Agent: Turnpike/6.07-S () Xref: g2news1.google.com comp.lang.ada:20914 Date: 2008-04-13T20:39:34+01:00 List-Id: In article , Jacob Sparre Andersen writes >I have found a rather annoying (but in some ways very reasonable) rule >in SPARK: > > You are not allowed to (re)declare operators for a type. > >This prevents me from using my standard trick for static unit type >checking: > > type Length is private; > function "+" (L, R : Length) return Length; -- not SPARK > ... > Meter : constant Length; > > type Area is private; > function "*" (L, R : Length) return Area; -- not SPARK > ... > >I have an idea for a (clumsy) solution: Generate two packages with >the same types (name-wise). The one as above, the other simply as: > > type Length is new Float; > type Area is new Float; > >Then I can use the liberal version with the SPARK tools, and swap the >restrictive in for the proper compilation. Ummmm, sorry no - derived types aren't allowed either (except for extending tagged record types). > >Any proposals for an elegant solution? The nearest you can get to derived types is simply: type Length is digits 6; but this will require type conversions that are not required by the "proper" version (and which will be required by the derived types as well). I guess the only way is an unconstrained subtype: subtype Length is Float; (hardly elegant, but ...) Phil Thornley -- JP Thornley