~singpolyma/dhall-ruby

9ea4cc33d98534011ab1160718082757cefc5ac0 — Stephen Paul Weber 4 years ago 45d912e
Start refactor of list concat
1 files changed, 12 insertions(+), 9 deletions(-)

M lib/dhall/typecheck.rb
M lib/dhall/typecheck.rb => lib/dhall/typecheck.rb +12 -9
@@ 272,20 272,23 @@ module Dhall
				@rhs = TypeChecker.for(expr.rhs)
			end

			module IsList
				def self.===(other)
					other.is_a?(Dhall::Application) &&
						other.function == Dhall::Variable["List"]
				end
			end

			def annotate(context)
				annotated_lhs = @lhs.annotate(context)
				annotated_rhs = @rhs.annotate(context)
				types = [annotated_lhs.type, annotated_rhs.type]
				valid_types = types.all? do |t|
					t.is_a?(Dhall::Application) &&
						t.function == Dhall::Variable["List"]
				end

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

				unless annotated_lhs.type == annotated_rhs.type
					raise TypeError, "Operator arguments do not match: #{types}"
				end
				TypeChecker.assert annotated_lhs.type, annotated_rhs.type,
				                   "Operator arguments do not match: #{types}"

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