Class: Rigor::Type::Difference

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from ValueSemantics

included

Constructor Details

#initialize(base, removed) ⇒ Difference

Returns a new instance of Difference.

Parameters:

  • base (Type::t)
  • removed (Type::t)


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

#baseType::t (readonly)

Returns the value of attribute base.

Returns:

  • (Type::t)


30
31
32
# File 'lib/rigor/type/difference.rb', line 30

def base
  @base
end

#removedType::t (readonly)

Returns the value of attribute removed.

Returns:

  • (Type::t)


30
31
32
# File 'lib/rigor/type/difference.rb', line 30

def removed
  @removed
end

Instance Method Details

#==Boolean

Parameters:

  • other (Object)

Returns:

  • (Boolean)


161
# File 'sig/rigor/type.rbs', line 161

def ==: (untyped other) -> bool

#acceptsAcceptsResult

Parameters:

  • other (Type::t)
  • mode: (accepts_mode)

Returns:



160
# File 'sig/rigor/type.rbs', line 160

def accepts: (Type::t other, ?mode: accepts_mode) -> AcceptsResult

#botTrinary

Returns:



55
56
57
# File 'lib/rigor/type/difference.rb', line 55

def bot
  Trinary.no
end

#describe(verbosity = :short) ⇒ String

Parameters:

  • verbosity (Symbol) (defaults to: :short)

Returns:

  • (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

#dynamicTrinary

Returns:



59
60
61
# File 'lib/rigor/type/difference.rb', line 59

def dynamic
  base.respond_to?(:dynamic) ? base.dynamic : Trinary.no
end

#erase_to_rbsString

Erases to the base nominal: every refinement MUST erase to its base per rbs-erasure.md.

Returns:

  • (String)


47
48
49
# File 'lib/rigor/type/difference.rb', line 47

def erase_to_rbs
  base.erase_to_rbs
end

#hashInteger

Returns:

  • (Integer)


162
# File 'sig/rigor/type.rbs', line 162

def hash: () -> Integer

#inspectString

Returns:

  • (String)


69
70
71
# File 'lib/rigor/type/difference.rb', line 69

def inspect
  "#<Rigor::Type::Difference #{describe(:short)}>"
end

#topTrinary

Returns:



51
52
53
# File 'lib/rigor/type/difference.rb', line 51

def top
  Trinary.no
end