Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ada > Re: SPARK and s...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 4 Topic 5650 of 5831
Post > Topic >>

Re: SPARK and static unit checking?

by JP Thornley <jpt@[EMAIL PROTECTED] > Apr 13, 2008 at 08:39 PM

In article 
<af9b42f7-b24c-4ca5-8a49-1ea9c15e1f37@[EMAIL PROTECTED]
>, 
Jacob Sparre Andersen <jspa@[EMAIL PROTECTED]
> 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
 




 4 Posts in Topic:
SPARK and static unit checking?
Jacob Sparre Andersen <  2008-04-11 02:59:20 
Re: SPARK and static unit checking?
JP Thornley <jpt@[EMAI  2008-04-13 20:39:34 
Re: SPARK and static unit checking?
Jacob Sparre Andersen <  2008-04-14 04:21:56 
Re: SPARK and static unit checking?
roderick.chapman@[EMAIL P  2008-04-14 07:57:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 20:51:33 CDT 2008.