comp.lang.ada
 help / color / mirror / Atom feed
From: J Kimball <nntp@kmbll.com>
Subject: Re: Making guarantees about record components
Date: Thu, 21 Nov 2013 23:46:28 -0600
Date: 2013-11-21T23:46:28-06:00	[thread overview]
Message-ID: <l6mr3m$bba$1@loke.gir.dk> (raw)
In-Reply-To: <l6gbro$1oc$1@loke.gir.dk>

On 11/19/2013 12:49 PM, J Kimball wrote:
> Hello
> 
> I'm trying to guarantee that two record component values map to the same
> value of another type.
> 
> type A is (...);
> type C is (...);
> 
> M : array (A) of C := (...);
> 
> type R is record
>    A1 : A;
>    A2 : A;
> end record
>    with Dynamic_Predicate => (M (R.A1) = M (R.A2) );
> 
> Is this the best solution we have as of Ada 2012?
> 
> Regards
> 

Thanks for your inputs. I understand the rules for the dynamic_predicate
as Kazakov pointed out. This is what you'd expect certainly. I was more
curious to see what solutions you might propose. My solution uses a
variant. Subtypes of A become the mapping. Static predicates make this
even more powerful. Assuming you can put up with a discriminated record,
this solution doesnt show off the power of static predicates, but
demonstrates one solution not using private types or predicates and fits
my actual problem well.

type A is (...);

subtype E is A range ...;
subtype F is A range ...;

type C is (...);

type R (One : A) is record
   case One is
      when E =>
         E_Value : E;
      when F =>
         F_Value : F;
   end case;
end record;




      parent reply	other threads:[~2013-11-22  5:46 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-19 18:49 Making guarantees about record components J Kimball
2013-11-19 20:20 ` Anh Vo
2013-11-19 22:57 ` Jeffrey Carter
2013-11-20  9:36   ` Stephen Leake
2013-11-20 17:37     ` Jeffrey Carter
2013-11-21  6:53       ` Stephen Leake
2013-11-20 20:58   ` tmoran
2013-11-19 23:38 ` Shark8
2013-11-20  8:01   ` Dmitry A. Kazakov
2013-11-22  5:46 ` J Kimball [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox