~singpolyma/dhall-ruby

2cd2c347d0b129c08cff3f0bb4aef597fcb432fb — Stephen Paul Weber 5 years ago f85cd48
Refactor AnonymousType typecheck
2 files changed, 12 insertions(+), 12 deletions(-)

M lib/dhall/typecheck.rb
M lib/dhall/util.rb
M lib/dhall/typecheck.rb => lib/dhall/typecheck.rb +6 -12
@@ 500,20 500,14 @@ module Dhall
					TypeChecker.for(mtype).annotate(context).type
				end

				if (bad = kinds.find { |t| !KINDS.include?(t) })
					raise TypeError, "AnonymousType field kind #{bad} "\
					                 "not one of #{KINDS}"
				end
				TypeChecker.assert (kinds - KINDS), [],
				                   "AnonymousType field kind not one of #{KINDS}"

				if (bad = kinds.find { |t| t != kinds.first })
					raise TypeError, "AnonymousType field kind #{bad} "\
					                 "does not match #{kinds.first}"
				end
				TypeChecker.assert kinds, Util::ArrayAllTheSame,
				                   "AnonymousType field kinds not all the same"

				Dhall::TypeAnnotation.new(
					value: @type,
					type:  kinds.first || KINDS.first
				)
				type = kinds.first || KINDS.first
				Dhall::TypeAnnotation.new(value: @type, type: type)
			end
		end


M lib/dhall/util.rb => lib/dhall/util.rb +6 -0
@@ 35,6 35,12 @@ module Dhall
			end
		end

		module ArrayAllTheSame
			def self.===(other)
				Array === other && other.all? { |x| x == other.first }
			end
		end

		def self.match_results(xs=nil, ys=nil)
			Array(xs).each_with_index.map do |r, idx|
				yield r, ys[idx]