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