Class: Rigor::Type::Difference
- Inherits:
-
Object
- Object
- Rigor::Type::Difference
- Includes:
- AcceptanceRouter, ValueSemantics
- Defined in:
- lib/rigor/type/difference.rb,
sig/rigor/type.rbs
Overview
Difference[base, removed] — the value set of base minus the value set of removed. Implements
the point-removal half of the OQ3 refinement-carrier strategy (ADR-3,
Working Decision Option C):
non-empty-string = Difference[Nominal[String], Constant[""]]
non-zero-int = Difference[Nominal[Integer], Constant[0]]
non-empty-array[T] = Difference[Nominal[Array, [T]], Tuple[]]
non-empty-hash[K,V] = Difference[Nominal[Hash, [K,V]], HashShape{}]
The carrier itself is structural: it stores base and removed as inner Type references and
answers projection / acceptance / display questions by composing those inner answers per the
lattice algebra in value-lattice.md. The
canonical-name registry (display side) lives in Rigor::Type::Combinator and prints kebab-case
names like non-empty-string for the recognised shapes; unrecognised differences fall back to the
raw base - removed operator form per type-operators.md.
Construction goes through Type::Combinator.difference / Combinator.non_empty_string etc. —
direct .new calls are an internal contract; callers MUST ensure both bounds are valid
Rigor::Type values and that removed is a subtype-or-equal of base (otherwise the difference
does not narrow anything and a normalisation upstream should collapse to base).
Instance Attribute Summary collapse
-
#base ⇒ Type::t
readonly
Returns the value of attribute base.
-
#removed ⇒ Type::t
readonly
Returns the value of attribute removed.
Instance Method Summary collapse
- #== ⇒ Boolean
- #accepts ⇒ AcceptsResult
- #bot ⇒ Trinary
- #describe(verbosity = :short) ⇒ String
- #dynamic ⇒ Trinary
-
#erase_to_rbs ⇒ String
Erases to the base nominal: every refinement MUST erase to its base per
rbs-erasure.md. - #hash ⇒ Integer
-
#initialize(base, removed) ⇒ Difference
constructor
A new instance of Difference.
- #inspect ⇒ String
- #top ⇒ Trinary
Methods included from ValueSemantics
Constructor Details
#initialize(base, removed) ⇒ Difference
Returns a new instance of Difference.
32 33 34 35 36 |
# File 'lib/rigor/type/difference.rb', line 32 def initialize(base, removed) @base = base @removed = removed freeze end |
Instance Attribute Details
#base ⇒ Type::t (readonly)
Returns the value of attribute base.
30 31 32 |
# File 'lib/rigor/type/difference.rb', line 30 def base @base end |
#removed ⇒ Type::t (readonly)
Returns the value of attribute removed.
30 31 32 |
# File 'lib/rigor/type/difference.rb', line 30 def removed @removed end |
Instance Method Details
#== ⇒ Boolean
161 |
# File 'sig/rigor/type.rbs', line 161
def ==: (untyped other) -> bool
|
#accepts ⇒ AcceptsResult
160 |
# File 'sig/rigor/type.rbs', line 160
def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult
|
#describe(verbosity = :short) ⇒ String
38 39 40 41 42 43 |
# File 'lib/rigor/type/difference.rb', line 38 def describe(verbosity = :short) named = canonical_name return named if named "#{base.describe(verbosity)} - #{removed.describe(verbosity)}" end |
#dynamic ⇒ Trinary
59 60 61 |
# File 'lib/rigor/type/difference.rb', line 59 def dynamic base.respond_to?(:dynamic) ? base.dynamic : Trinary.no end |
#erase_to_rbs ⇒ String
Erases to the base nominal: every refinement MUST erase to its base per
rbs-erasure.md.
47 48 49 |
# File 'lib/rigor/type/difference.rb', line 47 def erase_to_rbs base.erase_to_rbs end |
#hash ⇒ Integer
162 |
# File 'sig/rigor/type.rbs', line 162
def hash: () -> Integer
|
#inspect ⇒ String
69 70 71 |
# File 'lib/rigor/type/difference.rb', line 69 def inspect "#<Rigor::Type::Difference #{describe(:short)}>" end |