class Dhallish::Ast::LetInNode
(let varname [: expected_type] = varval)+ in … vars shall be [[varname1, expected_type1, varval1], …] where expected_type can be nil if no type was given
Attributes
inexpr[RW]
vars[RW]
Public Class Methods
new(vars, inexpr)
click to toggle source
# File lib/ast.rb, line 156 def initialize(vars, inexpr) @vars = vars @inexpr = inexpr end
Public Instance Methods
compute_type(ctx)
click to toggle source
# 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.metadata 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
evaluate(ctx)
click to toggle source
# File lib/ast.rb, line 182 def evaluate(ctx) newctx = Context.new(ctx) vars.each { |elm| varname, expected_type_ast, expr = elm val = expr.evaluate newctx newctx[varname] = val } inexpr.evaluate newctx end