class Dhall::AsDhall::UnionInferer

Public Class Methods

new(tagged={}) click to toggle source
# File lib/dhall/as_dhall.rb, line 52
def initialize(tagged={})
        @tagged = tagged
end

Public Instance Methods

disambiguate_against(tag, anno) click to toggle source
# File lib/dhall/as_dhall.rb, line 80
def disambiguate_against(tag, anno)
        self.class.new(
                @tagged.reject { |k, _| k == tag }.merge(
                        "#{tag}_#{@tagged[tag].type.digest.hexdigest}" => @tagged[tag],
                        "#{tag}_#{anno.type.digest.hexdigest}"         => anno
                )
        )
end
union_for(expr) click to toggle source
# File lib/dhall/as_dhall.rb, line 60
def union_for(expr)
        if expr.is_a?(Enum)
                tag = expr.tag
                expr = nil
        else
                tag = @tagged.keys.find { |k| @tagged[k].exprs.include?(expr) }
        end
        expr = expr.extract if expr.is_a?(Union)
        Union.from(union_type, tag, expr)
end
union_type() click to toggle source
# File lib/dhall/as_dhall.rb, line 56
def union_type
        UnionType.new(alternatives: Hash[@tagged.map { |k, v| [k, v.type] }])
end
with(tag, type_annotation) click to toggle source
# File lib/dhall/as_dhall.rb, line 71
def with(tag, type_annotation)
        anno = AnnotatedExpressionList.from(type_annotation)
        if @tagged.key?(tag) && @tagged[tag].type != anno.type
                disambiguate_against(tag, anno)
        else
                self.class.new(@tagged.merge(tag => anno) { |_, x, y| x + y })
        end
end