Class: Dhallish::Ast::FunctionType
- Inherits:
-
Object
- Object
- Dhallish::Ast::FunctionType
- Defined in:
- lib/ast.rb
Instance Attribute Summary collapse
-
#lhs ⇒ Object
Returns the value of attribute lhs.
-
#rhs ⇒ Object
Returns the value of attribute rhs.
-
#type_var ⇒ Object
Returns the value of attribute type_var.
Instance Method Summary collapse
- #compute_type(ctx) ⇒ Object
- #evaluate(ctx) ⇒ Object
-
#initialize(lhs, rhs, type_var = nil) ⇒ FunctionType
constructor
lhs and rhs should be values of type Type if Function Type contains “forall” , e.g.
Constructor Details
#initialize(lhs, rhs, type_var = nil) ⇒ FunctionType
lhs and rhs should be values of type Type if Function Type contains “forall” , e.g. “forall(t : Type) -> Natural”, type_var should contain the introduced label as a string otherwise, type_var shall be nil
571 572 573 574 575 |
# File 'lib/ast.rb', line 571 def initialize(lhs, rhs, type_var=nil) @lhs = lhs @rhs = rhs @type_var = type_var end |
Instance Attribute Details
#lhs ⇒ Object
Returns the value of attribute lhs.
564 565 566 |
# File 'lib/ast.rb', line 564 def lhs @lhs end |
#rhs ⇒ Object
Returns the value of attribute rhs.
565 566 567 |
# File 'lib/ast.rb', line 565 def rhs @rhs end |
#type_var ⇒ Object
Returns the value of attribute type_var.
566 567 568 |
# File 'lib/ast.rb', line 566 def type_var @type_var end |
Instance Method Details
#compute_type(ctx) ⇒ Object
577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 |
# File 'lib/ast.rb', line 577 def compute_type(ctx) lhs_type = @lhs.compute_type ctx assert ("Expression for argument type not a type") { lhs_type.is_a? Types::Type } lhs_type = lhs_type. new_ctx = ctx type_var = nil if !@type_var.nil? and lhs_type.is_a? Types::Type new_ctx = Context.new ctx lhs_type = new_ctx[@type_var] = Types::Type.new (Types::Unresolved.new @type_var) type_var = @type_var end rhs_type = @rhs.compute_type new_ctx assert ("Expression for result type not a type") { rhs_type.is_a? Types::Type } rhs_type = rhs_type. Types::Type.new (Types::Function.new lhs_type, rhs_type, type_var) end |
#evaluate(ctx) ⇒ Object
594 595 596 597 598 599 600 601 602 603 604 605 606 |
# File 'lib/ast.rb', line 594 def evaluate(ctx) lhs = @lhs.evaluate(ctx) if !type_var.nil? and lhs.is_a? Types::Type new_ctx = Context.new(ctx) new_ctx[type_var] = Types::Unresolved.new(type_var) rhs = @rhs.evaluate(new_ctx) else rhs = @rhs.evaluate(ctx) end Types::Function.new(lhs, rhs, type_var) end |