class Yadriggy::CompositeType

Parametric types.

Attributes

args[R]

@return [Array<Type>] type arguments.

ruby_class[R]

@return [Module] type name. The value is a Ruby class.

Public Class Methods

new(name, args) click to toggle source

@param [Module] name type name. @param [Array<Type>|Type] args type arguments.

# File lib/yadriggy/type.rb, line 567
def initialize(name, args)
  @ruby_class = name
  @args = args.is_a?(Array) ? args : [ args ]
end

Public Instance Methods

<=(t) click to toggle source

@api private Check the subtype relation. @param [Type] t the other type. @return [Boolean] true if `self` is equivalent to `t`

or a subtype of `t`.
# File lib/yadriggy/type.rb, line 597
def <= (t)
  if t.is_super_of?(self)
    true
  else
    ct = CompositeType.role(t)
    if ct.nil?
      RubyClass[@ruby_class] <= t
    else
      ct.ruby_class == @ruby_class &&
        @args.zip(ct.args).all? {|tt| tt[0] <= tt[1] }
    end
  end
end
==(t) click to toggle source

Checks the equality. @param [Type|Module] t the other object. @return [Boolean] true if `self` and `t` represent the same type

and their type arguments are equivalent.
# File lib/yadriggy/type.rb, line 581
def == (t)
  ct = CompositeType.role(t)
  !ct.nil? && ct.ruby_class == @ruby_class &&
    ct.args == @args
end
exact_type() click to toggle source

@api private

# File lib/yadriggy/type.rb, line 612
def exact_type
  @ruby_class
end
first_arg() click to toggle source

@return [Type] the first type argument.

# File lib/yadriggy/type.rb, line 573
def first_arg
  @args[0]
end
hash() click to toggle source

@api private

# File lib/yadriggy/type.rb, line 588
def hash
  @ruby_class.hash + @args.reduce(0) {|h,p| h + p.hash }
end
name() click to toggle source

Obtains the name of this type. @return [String] the type name.

# File lib/yadriggy/type.rb, line 623
def name
  name = @ruby_class.name
  name << '<' << @args.map{|e| e.name }.join(',') << '>'
  name
end
supertype() click to toggle source

@return [RubyClass] the {RubyClass} for this class.

# File lib/yadriggy/type.rb, line 617
def supertype
  RubyClass[@ruby_class]
end