From bccb3dd8f6e4d0bc7c6267f1c6b404865a14f5f2 Mon Sep 17 00:00:00 2001 From: Stephen Paul Weber Date: Sun, 31 Mar 2019 14:04:31 -0500 Subject: [PATCH] Refactor OperatorListConcatenate typecheck --- lib/dhall/typecheck.rb | 10 ++++------ lib/dhall/util.rb | 10 ++++++++++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/dhall/typecheck.rb b/lib/dhall/typecheck.rb index a182b61..e861b7c 100644 --- a/lib/dhall/typecheck.rb +++ b/lib/dhall/typecheck.rb @@ -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 diff --git a/lib/dhall/util.rb b/lib/dhall/util.rb index 46e4f66..ca640f5 100644 --- a/lib/dhall/util.rb +++ b/lib/dhall/util.rb @@ -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 -- 2.38.5