Class: FunctionType
- Inherits:
-
Object
- Object
- FunctionType
- Defined in:
- lib/support.rb
Instance Attribute Summary collapse
-
#formal_types ⇒ Object
Returns the value of attribute formal_types.
-
#receiver_type ⇒ Object
Returns the value of attribute receiver_type.
-
#return_type ⇒ Object
Returns the value of attribute return_type.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(receiver_type, formal_types, return_type) ⇒ FunctionType
constructor
A new instance of FunctionType.
- #to_s ⇒ Object
- #unify_components(other) ⇒ Object
Constructor Details
#initialize(receiver_type, formal_types, return_type) ⇒ FunctionType
Returns a new instance of FunctionType.
114 115 116 117 118 119 |
# File 'lib/support.rb', line 114 def initialize(receiver_type, formal_types, return_type) raise "nil not allowed" if formal_types.nil? or return_type.nil? @receiver_type = receiver_type @formal_types = formal_types @return_type = return_type end |
Instance Attribute Details
#formal_types ⇒ Object
Returns the value of attribute formal_types.
111 112 113 |
# File 'lib/support.rb', line 111 def formal_types @formal_types end |
#receiver_type ⇒ Object
Returns the value of attribute receiver_type.
110 111 112 |
# File 'lib/support.rb', line 110 def receiver_type @receiver_type end |
#return_type ⇒ Object
Returns the value of attribute return_type.
112 113 114 |
# File 'lib/support.rb', line 112 def return_type @return_type end |
Instance Method Details
#==(other) ⇒ Object
121 122 123 124 125 126 127 128 |
# File 'lib/support.rb', line 121 def ==(other) return nil unless other.class == self.class return false unless other.receiver_type == self.receiver_type return false unless other.return_type == self.return_type return false unless other.formal_types == self.formal_types return true end |
#to_s ⇒ Object
144 145 146 147 148 149 150 |
# File 'lib/support.rb', line 144 def to_s formals = formal_types.map do |t| t.inspect end "function(#{receiver_type.inspect}, [#{formals.join ', '}], #{return_type.inspect})" end |
#unify_components(other) ⇒ Object
130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/support.rb', line 130 def unify_components(other) raise TypeError, "Unable to unify: different number of args #{self.inspect} vs #{other.inspect}" unless @formal_types.length == other.formal_types.length @formal_types.each_with_index do |t, i| t.unify other.formal_types[i] end @receiver_type.unify other.receiver_type @return_type.unify other.return_type # rescue RuntimeError # print more complete warning message # raise "Unable to unify\n#{self}\nwith\n#{other}" end |