~singpolyma/dhall-ruby

bccb3dd8f6e4d0bc7c6267f1c6b404865a14f5f2 — Stephen Paul Weber 4 years ago 9ea4cc3
Refactor OperatorListConcatenate typecheck
2 files changed, 14 insertions(+), 6 deletions(-)

M lib/dhall/typecheck.rb
M lib/dhall/util.rb
M lib/dhall/typecheck.rb => lib/dhall/typecheck.rb +4 -6
@@ 284,15 284,13 @@ module Dhall
				annotated_rhs = @rhs.annotate(context)

				types = [annotated_lhs.type, annotated_rhs.type]
				TypeChecker.assert types, Util::ArrayOf.new(IsList),
				                   "Operator arguments not List: #{types}"

				TypeChecker.assert annotated_lhs.type, annotated_rhs.type,
				                   "Operator arguments do not match: #{types}"
				assertion = Util::ArrayOf.new(Util::AllOf.new(IsList, types.first))
				TypeChecker.assert types, assertion,
				                   "Operator arguments wrong: #{types}"

				Dhall::TypeAnnotation.new(
					value: @expr.with(lhs: annotated_lhs, rhs: annotated_rhs),
					type:  annotated_lhs.type
					type:  types.first
				)
			end
		end

M lib/dhall/util.rb => lib/dhall/util.rb +10 -0
@@ 2,6 2,16 @@

module Dhall
	module Util
		class AllOf
			def initialize(*validators)
				@validators = validators
			end

			def ===(other)
				@validators.all? { |v| v === other }
			end
		end

		class ArrayOf < ValueSemantics::ArrayOf
			def initialize(element_validator, min: 0, max: Float::INFINITY)
				@min = min