Class: SFRP::Poly::FuncTyping

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(param_size, &block) ⇒ FuncTyping

Returns a new instance of FuncTyping.



99
100
101
102
103
# File 'lib/sfrp/poly/typing.rb', line 99

def initialize(param_size, &block)
  @params = Array.new(param_size) { Typing.new }
  @body = Typing.new
  block.call(self) if block
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



97
98
99
# File 'lib/sfrp/poly/typing.rb', line 97

def body
  @body
end

#paramsObject (readonly)

Returns the value of attribute params.



97
98
99
# File 'lib/sfrp/poly/typing.rb', line 97

def params
  @params
end

Instance Method Details

#instance(&block) ⇒ Object



118
119
120
121
122
# File 'lib/sfrp/poly/typing.rb', line 118

def instance(&block)
  instance = to_ftype_annot.to_ftyping
  block.call(instance) if block
  instance
end

#mono?Boolean

Returns:

  • (Boolean)


129
130
131
# File 'lib/sfrp/poly/typing.rb', line 129

def mono?
  [@body, *@params].all?(&:mono?)
end

#to_ftype_annotObject



105
106
107
108
109
# File 'lib/sfrp/poly/typing.rb', line 105

def to_ftype_annot
  vars = @body.variables + @params.flat_map(&:variables)
  args = @params.map { |t| t.to_type_annot(vars) }
  FuncTypeAnnotation.new(@body.to_type_annot(vars), args)
end

#to_sObject



133
134
135
# File 'lib/sfrp/poly/typing.rb', line 133

def to_s
  to_ftype_annot.to_s
end

#unify(other) ⇒ Object



111
112
113
114
115
116
# File 'lib/sfrp/poly/typing.rb', line 111

def unify(other)
  raise unless @params.size == other.params.size
  @params.zip(other.params) { |a, b| a.unify(b) }
  @body.unify(other.body)
  self
end

#unique_strObject



124
125
126
127
# File 'lib/sfrp/poly/typing.rb', line 124

def unique_str
  args = @params + [@body]
  "Func#{@params.size}[#{args.map(&:unique_str).join(', ')}]"
end