Sha256: 6f50124c1deb03f435e5032cc502c28bfe67645573fbe70c2be67ec22e2cebef

Contents?: true

Size: 1.47 KB

Versions: 41

Compression:

Stored size: 1.47 KB

Contents

module RBS
  # Substitution from type variables to types.
  #
  # The substitution construction is in _destructive_ manner.
  #
  #    sub = Substitution.new
  #    sub.add(from: :A, to: type1)
  #    sub.add(from: :B, to: type2)
  #    sub.instance_type = type3
  #
  class Substitution
    # A hash containing mapping from type variable name to type.
    attr_reader mapping: Hash[Symbol, Types::t]

    # The result of applying this substitution to `instance` type.
    # `nil` maps to `instance` type itself.
    attr_accessor instance_type: Types::t?

    def initialize: () -> void

    # Add mapping to this substitution.
    # Overwrites the previous mapping if same `from` is given.
    def add: (from: Symbol, to: Types::t) -> void

    # Utility method to construct a substitution.
    # Raises an error when `variables.size != types.size`.
    # `instance_type` defaults to `nil`.
    #
    # Yields types in `types` and the block value is used if block is given.
    #
    def self.build: (Array[Symbol] variables, Array[Types::t] types, ?instance_type: Types::t?) ?{ (Types::t) -> Types::t } -> instance

    # Applies the substitution to given type.
    def apply: (Types::t) -> Types::t

    # Returns a substitution without variables given in `vars`.
    def without: (*Symbol vars) -> Substitution

    # Returns true if given substitution is identity.
    def empty?: () -> bool

    alias [] apply

    # (s1 + s2)[t] == s2[s1[t]]
    # 
    def +: (Substitution) -> Substitution
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
rbs-3.7.0.dev.1 sig/substitution.rbs
rbs-3.6.1 sig/substitution.rbs
rbs-3.6.0 sig/substitution.rbs
rbs-3.6.0.pre.3 sig/substitution.rbs
rbs-3.6.0.pre.2 sig/substitution.rbs
rbs-3.6.0.pre.1 sig/substitution.rbs
rbs-3.6.0.dev.1 sig/substitution.rbs
rbs-3.5.3 sig/substitution.rbs
rbs-3.5.2 sig/substitution.rbs
rbs-3.5.1 sig/substitution.rbs
rbs-3.5.1.pre.1 sig/substitution.rbs
rbs-3.5.0 sig/substitution.rbs
rbs-3.5.0.pre.2 sig/substitution.rbs
rbs-3.5.0.pre.1 sig/substitution.rbs
rbs-3.4.4 sig/substitution.rbs
rbs-3.4.3 sig/substitution.rbs
rbs-3.4.2 sig/substitution.rbs
rbs-3.4.1 sig/substitution.rbs
rbs-3.4.0 sig/substitution.rbs
rbs-3.4.0.pre.1 sig/substitution.rbs