Su(per)btypes in Ada 2012 – Part 1

If you want to learn a bit about types and the Static_Predicate aspect in Ada 2012, then this AdaCore gem has the good stuff:

Ada 2012 is full of features for specifying a rich set of type properties. In this series of three Gems, we describe three aspects that can be used to state invariant properties of types and subtypes. This first Gem is concerned with the Static_Predicate aspect.

With the Static_Predicate aspect you can do cool stuff like this:

type Day is (Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday);
type T_Day is new Day with Static_Predicate => T_Day in Tuesday | Thursday;

Nice eh’? The compiler will now protect you against assigning Friday to a T_Day. That is pretty neat. Stay tuned for part 2 and 3, where more of the Ada 2012 goodness will be explained.

Leave a Reply