|
@@ -41,12 +41,37 @@ mismatch). Suite: `GenericProg`, `PairProg`, `BufProg`, `g_badbuf`,
|
|
|
cleanly; verified). The only "same instance twice" case is a
|
|
cleanly; verified). The only "same instance twice" case is a
|
|
|
refinement's DEFINITION and IMPLEMENTATION, which must instantiate
|
|
refinement's DEFINITION and IMPLEMENTATION, which must instantiate
|
|
|
the generic's def and impl respectively.
|
|
the generic's def and impl respectively.
|
|
|
-- **`GENERIC CLASS`** — needs a **design decision**, not extension: the
|
|
|
|
|
- current machinery instantiates *modules* by re-parsing a source file.
|
|
|
|
|
- A generic *class* has no natural refinement form yet (a class is a
|
|
|
|
|
- type declared inside a module; instantiating it would re-parse its
|
|
|
|
|
- enclosing module, or require a `TYPE C = GClass(args)` type-refinement
|
|
|
|
|
- affordance). Until that syntax is chosen, this stays open.
|
|
|
|
|
|
|
+- **`GENERIC CLASS`** — **already achievable through generic
|
|
|
|
|
+ modules** (verified, suite `GCBoxProg`): declare the class in the
|
|
|
|
|
+ generic module's `TYPE` block, implement it in the generic impl, and
|
|
|
|
|
+ instantiate the module:
|
|
|
|
|
+
|
|
|
|
|
+ ```modula2
|
|
|
|
|
+ GENERIC DEFINITION MODULE GBox (T : TYPE);
|
|
|
|
|
+ TYPE
|
|
|
|
|
+ CLASS Box;
|
|
|
|
|
+ v : T;
|
|
|
|
|
+ PROCEDURE Put(x : T);
|
|
|
|
|
+ PROCEDURE Get() : T;
|
|
|
|
|
+ END Box;
|
|
|
|
|
+ END GBox.
|
|
|
|
|
+ * GBox's CLASS IMPLEMENTATION Box holds the method bodies;
|
|
|
|
|
+ DEFINITION/IMPLEMENTATION MODULE GCInt = GBox(INTEGER);
|
|
|
|
|
+ (* program: *) b : GCInt.Box; b.Put(42); ExitCode := b.Get()
|
|
|
|
|
+ ```
|
|
|
|
|
+
|
|
|
|
|
+ So **no standalone `GENERIC CLASS` syntax is required** for the
|
|
|
|
|
+ capability. Standalone syntax would only matter if a class must be
|
|
|
|
|
+ instantiated *without* a whole generic module; the principled form
|
|
|
|
|
+ for that is a **type refinement** (`TYPE IntStack = Stack(INTEGER);`),
|
|
|
|
|
+ which mirrors `MODULE X = G(args)` at type level but needs the
|
|
|
|
|
+ class's `CLASS IMPLEMENTATION` block re-parsed/renamed per instance —
|
|
|
|
|
+ a design of its own. Recommendation: keep the generic-module pattern.
|
|
|
|
|
+
|
|
|
|
|
+ Minor asymmetry noted: a class is accepted as a top-level item in an
|
|
|
|
|
+ IMPLEMENTATION/program `DeclSeq` but not in a DEFINITION unit's item
|
|
|
|
|
+ list (only inside a `TYPE` block) — harmless, but a tidy-up
|
|
|
|
|
+ candidate.
|
|
|
|
|
|
|
|
## Résumé
|
|
## Résumé
|
|
|
|
|
|