A CLOSER LOOK
Ada Programming is a community-written guide with separate chapters on the type system and packages. One useful route into the book is to ask what a declaration tells the compiler about a value. The Type System chapter develops that question through distinct types and constrained subtypes.
Consider a day-of-month value constrained to the integers from 1 through 31. That range makes a specific rule visible in the program. AdaCore’s introduction demonstrates how programmers define numeric ranges; the Wikibooks chapter explains that range checks can raise Constraint_Error during execution. Checking a value is therefore part of the program’s behavior, and some checks occur while it runs.
The chapter also distinguishes a new type from a subtype. Creating distinct integer types for quantities such as distance and duration gives them different type identities. A direct assignment between those distinct types is rejected without the required explicit conversion. A subtype places constraints on an existing type, retaining that underlying identity. The choice expresses what kinds of values the programmer intends to keep separate.
The calendar example exposes a boundary of this approach: 31 lies within the chosen range even when the month is February. Calendar validity also depends on the month and year. The range captures one useful condition; a fuller model needs additional rules. This is an original example for reading the tutorial, with no claim that the book supplies a complete calendar implementation.
The generated illustration uses fitted modules as a metaphor for declared boundaries. It is conceptual artwork. The source chapters provide the technical explanation and examples; the image is not a specification or evidence that a program is correct.
Educational discussion adapted from Wikibooks contributors · CC BY-SA 4.0 · Source credits · License and reuse terms