Class: SFRP::Poly::FuncTyping
- Inherits:
-
Object
- Object
- SFRP::Poly::FuncTyping
- Defined in:
- lib/sfrp/poly/typing.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#params ⇒ Object
readonly
Returns the value of attribute params.
Instance Method Summary collapse
-
#initialize(param_size, &block) ⇒ FuncTyping
constructor
A new instance of FuncTyping.
- #instance(&block) ⇒ Object
- #mono? ⇒ Boolean
- #to_ftype_annot ⇒ Object
- #to_s ⇒ Object
- #unify(other) ⇒ Object
- #unique_str ⇒ Object
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
#body ⇒ Object (readonly)
Returns the value of attribute body.
97 98 99 |
# File 'lib/sfrp/poly/typing.rb', line 97 def body @body end |
#params ⇒ Object (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
129 130 131 |
# File 'lib/sfrp/poly/typing.rb', line 129 def mono? [@body, *@params].all?(&:mono?) end |
#to_ftype_annot ⇒ Object
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_s ⇒ Object
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_str ⇒ Object
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 |