Class: Dhallish::Ast::LetInNode
- Inherits:
-
Object
- Object
- Dhallish::Ast::LetInNode
- Defined in:
- lib/ast.rb
Overview
(let varname [: expected_type] = varval)+ in … vars shall be [[varname1, expected_type1, varval1], …] where expected_type can be nil if no type was given
Instance Attribute Summary collapse
-
#inexpr ⇒ Object
Returns the value of attribute inexpr.
-
#vars ⇒ Object
Returns the value of attribute vars.
Instance Method Summary collapse
- #compute_type(ctx) ⇒ Object
- #evaluate(ctx) ⇒ Object
-
#initialize(vars, inexpr) ⇒ LetInNode
constructor
A new instance of LetInNode.
Constructor Details
#initialize(vars, inexpr) ⇒ LetInNode
Returns a new instance of LetInNode.
156 157 158 159 |
# File 'lib/ast.rb', line 156 def initialize(vars, inexpr) @vars = vars @inexpr = inexpr end |
Instance Attribute Details
#inexpr ⇒ Object
Returns the value of attribute inexpr.
155 156 157 |
# File 'lib/ast.rb', line 155 def inexpr @inexpr end |
#vars ⇒ Object
Returns the value of attribute vars.
154 155 156 |
# File 'lib/ast.rb', line 154 def vars @vars end |
Instance Method Details
#compute_type(ctx) ⇒ Object
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/ast.rb', line 161 def compute_type(ctx) new_ctx = Context.new ctx @vars.each { |decl| name, annot_type_expr, val = decl act_type = val.compute_type(new_ctx) if !annot_type_expr.nil? type_type = annot_type_expr.compute_type(new_ctx) assert ("not a type after type annotation") { type_type.is_a? Types::Type } annot_type = type_type. unification = Types::unification(annot_type, act_type) assert ("Actual type of #{name}'s value (#{act_type}) doesn't match annotated type (#{annot_type})") { !unification.nil? } end new_ctx[name] = act_type } @inexpr.compute_type new_ctx end |