Class: SFRP::Poly::Pattern
- Inherits:
-
Object
- Object
- SFRP::Poly::Pattern
- Defined in:
- lib/sfrp/poly/expression.rb
Instance Method Summary collapse
- #clone ⇒ Object
-
#initialize(vconst_str, ref_var_str, patterns, id = nil) ⇒ Pattern
constructor
A new instance of Pattern.
- #to_mono(monofier) ⇒ Object
- #typing(set, var_env) ⇒ Object
Constructor Details
#initialize(vconst_str, ref_var_str, patterns, id = nil) ⇒ Pattern
Returns a new instance of Pattern.
131 132 133 134 135 136 |
# File 'lib/sfrp/poly/expression.rb', line 131 def initialize(vconst_str, ref_var_str, patterns, id = nil) @vconst_str = vconst_str @ref_var_str = ref_var_str @patterns = patterns @id = id end |
Instance Method Details
#clone ⇒ Object
153 154 155 |
# File 'lib/sfrp/poly/expression.rb', line 153 def clone Pattern.new(@vconst_str, @ref_var_str, @patterns.map(&:clone), @id) end |
#to_mono(monofier) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/sfrp/poly/expression.rb', line 157 def to_mono(monofier) raise UndeterminableTypeError.new(@id, @typing) unless @typing.mono? mono_type_str = monofier.use_type(@typing) if @vconst_str mono_vconst_str = monofier.use_vconst(@vconst_str, @typing) ch = @patterns.map { |pat| pat.to_mono(monofier) } M.pref(mono_type_str, mono_vconst_str, @ref_var_str, *ch) else M.pany(mono_type_str, @ref_var_str) end end |
#typing(set, var_env) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/sfrp/poly/expression.rb', line 138 def typing(set, var_env) raise if @typing @typing = Typing.new do |t| var_env[@ref_var_str] = t if @ref_var_str if @vconst_str set.vconst(@vconst_str).ftyping.instance do |ft| @patterns.zip(ft.params) do |pat, param_typing| pat.typing(set, var_env).unify(param_typing) end ft.body.unify(t) end end end end |