Class: SFRP::Poly::FuncTypeAnnotation

Inherits:
Object
  • Object
show all
Defined in:
lib/sfrp/poly/typing.rb

Instance Method Summary collapse

Constructor Details

#initialize(ret_type_annot, arg_type_annots) ⇒ FuncTypeAnnotation

Returns a new instance of FuncTypeAnnotation.



139
140
141
142
# File 'lib/sfrp/poly/typing.rb', line 139

def initialize(ret_type_annot, arg_type_annots)
  @ret_type_annot = ret_type_annot
  @arg_type_annots = arg_type_annots
end

Instance Method Details

#to_ftyping(var_strs = nil) ⇒ Object



144
145
146
147
148
149
150
151
# File 'lib/sfrp/poly/typing.rb', line 144

def to_ftyping(var_strs = nil)
  var_strs ||= [@ret_type_annot, *@arg_type_annots].flat_map(&:var_strs)
  tbl = Hash[var_strs.uniq.map { |s| [s, Typing.new] }]
  FuncTyping.new(@arg_type_annots.size) do |ft|
    ft.params.zip(@arg_type_annots) { |t, at| t.unify(at.to_typing(tbl)) }
    ft.body.unify(@ret_type_annot.to_typing(tbl))
  end
end

#to_sObject



153
154
155
# File 'lib/sfrp/poly/typing.rb', line 153

def to_s
  "(#{@arg_type_annots.map(&:to_s).join(', ')}) -> #{@ret_type_annot}"
end