~singpolyma/dhall-ruby

f8217b0819802b4789065c1c28a659d887f1d54e — Stephen Paul Weber 3 years ago eead61e
Clean up style violations
M lib/dhall/ast.rb => lib/dhall/ast.rb +12 -9
@@ 114,7 114,8 @@ module Dhall
		def flatten
			f, args = if function.is_a?(Application)
				function.flatten
			elsif function.is_a?(Builtin) && (unfilled = function.unfill).is_a?(Application)
			elsif function.is_a?(Builtin) &&
			      (unfilled = function.unfill).is_a?(Application)
				unfilled.flatten
			else
				[function, []]


@@ 221,7 222,7 @@ module Dhall
		def as_json
			if name == "_"
				index
			elsif index == 0
			elsif index.zero?
				name
			else
				[name, index]


@@ 811,10 812,12 @@ module Dhall
				fragment  Either(nil, ::String)
			end)

			HeaderType = RecordType.new(record: {
				"header" => Variable["Text"],
				"value"  => Variable["Text"]
			})
			HeaderType = RecordType.new(
				record: {
					"header" => Variable["Text"],
					"value"  => Variable["Text"]
				}
			)

			def initialize(headers, authority, *path, query, fragment)
				super(


@@ 986,11 989,11 @@ module Dhall
			end

			def check(expr)
				if @protocol == :nocheck || expr.cache_key == to_s
					expr
				else
				if @protocol != :nocheck && expr.cache_key != to_s
					raise FailureException, "#{expr} does not match #{self}"
				end

				expr
			end

			def as_json

M lib/dhall/binary.rb => lib/dhall/binary.rb +4 -3
@@ 45,10 45,11 @@ module Dhall
	end

	class Application
		def self.decode(f, *args)
			args.map(&Dhall.method(:decode)).reduce(Dhall.decode(f)) { |f, arg|
		def self.decode(function, *args)
			function = Dhall.decode(function)
			args.map(&Dhall.method(:decode)).reduce(function) do |f, arg|
				new(function: f, argument: arg)
			}
			end
		end
	end


M lib/dhall/builtins.rb => lib/dhall/builtins.rb +3 -3
@@ 27,7 27,7 @@ module Dhall
			if (unfilled = unfill).class != self.class
				unfilled.as_json
			else
				self.class.name.split(/::/).last.gsub(/_/, "/")
				self.class.name.split(/::/).last.tr("_", "/")
			end
		end



@@ 386,9 386,9 @@ module Dhall

			def call(*args)
				args.reduce(self) do |fold, arg|
					fold.fill_or_call(arg) {
					fold.fill_or_call(arg) do
						fold.optional.reduce(arg, &fold.f)
					} || super
					end || super
				end
			end
		end

M lib/dhall/normalize.rb => lib/dhall/normalize.rb +6 -6
@@ 236,15 236,15 @@ module Dhall
	end

	class List
			def normalize
				super.with(type: nil)
			end
		def normalize
			super.with(type: nil)
		end
	end

	class EmptyList
			def normalize
				super.with(type: type.normalize)
			end
		def normalize
			super.with(type: type.normalize)
		end
	end

	class Optional

M lib/dhall/resolve.rb => lib/dhall/resolve.rb +4 -2
@@ 138,7 138,8 @@ module Dhall
			end

			def resolve_http(http_source)
				ExpressionResolver.for(http_source.headers)
				ExpressionResolver
					.for(http_source.headers)
					.resolve(self).then do |headers|
					@http_resolutions.register(
						http_source.with(headers: headers.normalize)


@@ 147,7 148,8 @@ module Dhall
			end

			def resolve_https(https_source)
				ExpressionResolver.for(https_source.headers)
				ExpressionResolver
					.for(https_source.headers)
					.resolve(self).then do |headers|
					@https_resolutions.register(
						https_source.with(headers: headers.normalize)

M lib/dhall/typecheck.rb => lib/dhall/typecheck.rb +46 -48
@@ 91,9 91,9 @@ module Dhall

			def shift(amount, name, min_index)
				self.class.new(@bindings.merge(
					Hash[@bindings.map { |var, bindings|
					Hash[@bindings.map do |var, bindings|
						[var, bindings.map { |b| b.shift(amount, name, min_index) }]
					}]
					end]
				))
			end
		end


@@ 136,9 136,7 @@ module Dhall
			}.freeze

			def annotate(context)
				if @var.name == "Sort"
					raise TypeError, "Sort has no Type, Kind, or Sort"
				end
				raise TypeError, "Sort has no Type, Kind, or Sort" if @var.name == "Sort"

				Dhall::TypeAnnotation.new(
					value: @var,


@@ 203,7 201,7 @@ module Dhall

				annotated_then = @then.annotate(context)
				then_type_type = TypeChecker.for(annotated_then.type)
				                 .annotate(context).type
				                            .annotate(context).type
				if then_type_type != Dhall::Variable["Type"]
					raise TypeError, "If branches must have types of type Type"
				end


@@ 216,7 214,7 @@ module Dhall
							then:      annotated_then,
							else:      annotated_else
						),
						type: annotated_then.type
						type:  annotated_then.type
					)
				else
					raise TypeError, "If branches have mismatched types: " \


@@ 264,9 262,7 @@ module Dhall
						t.function == Dhall::Variable["List"]
				end

				unless valid_types
					raise TypeError, "Operator arguments not List: #{types}"
				end
				raise TypeError, "Operator arguments not List: #{types}" unless valid_types

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


@@ 480,10 476,10 @@ module Dhall
				@expr = expr
			end

			def annotate(context)
			def annotate(*)
				Dhall::TypeAnnotation.new(
					value: @expr,
					type: Dhall::Variable["Type"]
					type:  Dhall::Variable["Type"]
				)
			end
		end


@@ 510,7 506,7 @@ module Dhall

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


@@ 520,10 516,10 @@ module Dhall
				@expr = expr
			end

			def annotate(context)
			def annotate(*)
				Dhall::TypeAnnotation.new(
					value: @expr,
					type: Dhall::EmptyRecordType.new
					type:  Dhall::EmptyRecordType.new
				)
			end
		end


@@ 547,7 543,7 @@ module Dhall

				Dhall::TypeAnnotation.new(
					value: arecord,
					type: type
					type:  type
				)
			end
		end


@@ 625,8 621,8 @@ module Dhall

				type = Dhall::UnionType.new(
					alternatives: Hash[@union.alternatives.alternatives.merge(
							@union.tag => annotated_value.type
						).sort]
						@union.tag => annotated_value.type
					).sort]
				)

				# Annotate to sanity check


@@ 634,7 630,7 @@ module Dhall

				Dhall::TypeAnnotation.new(
					value: @union.with(value: annotated_value),
					type: type
					type:  type
				)
			end
		end


@@ 658,7 654,7 @@ module Dhall
					raise TypeError, "Merge expected Union got: #{aunion.type}"
				end

				type = arecord.type.record.reduce(@merge.type) do |type, (k, htype)|
				type = arecord.type.record.reduce(@merge.type) do |type_acc, (k, htype)|
					unless aunion.type.alternatives.key?(k)
						raise TypeError, "Merge handler for unknown alternative: #{k}"
					end


@@ 667,7 663,7 @@ module Dhall
						raise TypeError, "Merge handlers must all be functions"
					end

					if type && htype.body != type
					if type_acc && htype.body != type_acc
						raise TypeError, "Handler output types must all match"
					end



@@ 753,7 749,7 @@ module Dhall

				Dhall::TypeAnnotation.new(
					value: @func.with(body: abody),
					type: type
					type:  type
				)
			end
		end


@@ 785,7 781,7 @@ module Dhall

				Dhall::TypeAnnotation.new(
					value: @app.with(function: afunc, argument: aarg),
					type: type
					type:  type
				)
			end
		end


@@ 823,7 819,7 @@ module Dhall

				Dhall::TypeAnnotation.new(
					value: ablock,
					type: abody.type
					type:  abody.type
				)
			end
		end


@@ 852,7 848,7 @@ module Dhall
			end

			TYPES = {
				"Natural/build" => Dhall::Forall.of_arguments(
				"Natural/build"     => Dhall::Forall.of_arguments(
					Dhall::Forall.new(
						var:  "natural",
						type: Dhall::Variable["Type"],


@@ 871,7 867,7 @@ module Dhall
					),
					body: Dhall::Variable["Natural"]
				),
				"Natural/fold" => Dhall::Forall.of_arguments(
				"Natural/fold"      => Dhall::Forall.of_arguments(
					Dhall::Variable["Natural"],
					body: Dhall::Forall.new(
						var:  "natural",


@@ 890,15 886,15 @@ module Dhall
						)
					)
				),
				"Natural/isZero" => Dhall::Forall.of_arguments(
				"Natural/isZero"    => Dhall::Forall.of_arguments(
					Dhall::Variable["Natural"],
					body: Dhall::Variable["Bool"]
				),
				"Natural/even" => Dhall::Forall.of_arguments(
				"Natural/even"      => Dhall::Forall.of_arguments(
					Dhall::Variable["Natural"],
					body: Dhall::Variable["Bool"]
				),
				"Natural/odd" => Dhall::Forall.of_arguments(
				"Natural/odd"       => Dhall::Forall.of_arguments(
					Dhall::Variable["Natural"],
					body: Dhall::Variable["Bool"]
				),


@@ 906,15 902,15 @@ module Dhall
					Dhall::Variable["Natural"],
					body: Dhall::Variable["Integer"]
				),
				"Natural/show" => Dhall::Forall.of_arguments(
				"Natural/show"      => Dhall::Forall.of_arguments(
					Dhall::Variable["Natural"],
					body: Dhall::Variable["Text"]
				),
				"Text/show" => Dhall::Forall.of_arguments(
				"Text/show"         => Dhall::Forall.of_arguments(
					Dhall::Variable["Text"],
					body: Dhall::Variable["Text"]
				),
				"List/build" => Dhall::Forall.new(
				"List/build"        => Dhall::Forall.new(
					var:  "a",
					type: Dhall::Variable["Type"],
					body: Dhall::Forall.of_arguments(


@@ 941,7 937,7 @@ module Dhall
						)
					)
				),
				"List/fold" => Dhall::Forall.new(
				"List/fold"         => Dhall::Forall.new(
					var:  "a",
					type: Dhall::Variable["Type"],
					body: Dhall::Forall.of_arguments(


@@ 968,7 964,7 @@ module Dhall
						)
					)
				),
				"List/length" => Dhall::Forall.new(
				"List/length"       => Dhall::Forall.new(
					var:  "a",
					type: Dhall::Variable["Type"],
					body: Dhall::Forall.of_arguments(


@@ 979,7 975,7 @@ module Dhall
						body: Dhall::Variable["Natural"]
					)
				),
				"List/head" => Dhall::Forall.new(
				"List/head"         => Dhall::Forall.new(
					var:  "a",
					type: Dhall::Variable["Type"],
					body: Dhall::Forall.of_arguments(


@@ 993,7 989,7 @@ module Dhall
						)
					)
				),
				"List/last" => Dhall::Forall.new(
				"List/last"         => Dhall::Forall.new(
					var:  "a",
					type: Dhall::Variable["Type"],
					body: Dhall::Forall.of_arguments(


@@ 1007,7 1003,7 @@ module Dhall
						)
					)
				),
				"List/indexed" => Dhall::Forall.new(
				"List/indexed"      => Dhall::Forall.new(
					var:  "a",
					type: Dhall::Variable["Type"],
					body: Dhall::Forall.of_arguments(


@@ 1017,14 1013,16 @@ module Dhall
						),
						body: Dhall::Application.new(
							function: Dhall::Variable["List"],
							argument: Dhall::RecordType.new(record: {
								"index" => Dhall::Variable["Natural"],
								"value" => Dhall::Variable["a"]
							})
							argument: Dhall::RecordType.new(
								record: {
									"index" => Dhall::Variable["Natural"],
									"value" => Dhall::Variable["a"]
								}
							)
						)
					)
				),
				"List/reverse" => Dhall::Forall.new(
				"List/reverse"      => Dhall::Forall.new(
					var:  "a",
					type: Dhall::Variable["Type"],
					body: Dhall::Forall.of_arguments(


@@ 1038,7 1036,7 @@ module Dhall
						)
					)
				),
				"Optional/fold" => Dhall::Forall.new(
				"Optional/fold"     => Dhall::Forall.new(
					var:  "a",
					type: Dhall::Variable["Type"],
					body: Dhall::Forall.of_arguments(


@@ 1064,7 1062,7 @@ module Dhall
						)
					)
				),
				"Optional/build" => Dhall::Forall.new(
				"Optional/build"    => Dhall::Forall.new(
					var:  "a",
					type: Dhall::Variable["Type"],
					body: Dhall::Forall.of_arguments(


@@ 1090,18 1088,18 @@ module Dhall
						)
					)
				),
				"Integer/show" => Dhall::Forall.of_arguments(
				"Integer/show"      => Dhall::Forall.of_arguments(
					Dhall::Variable["Integer"],
					body: Dhall::Variable["Text"]
				),
				"Integer/toDouble" => Dhall::Forall.of_arguments(
				"Integer/toDouble"  => Dhall::Forall.of_arguments(
					Dhall::Variable["Integer"],
					body: Dhall::Variable["Double"]
				),
				"Double/show" => Dhall::Forall.of_arguments(
				"Double/show"       => Dhall::Forall.of_arguments(
					Dhall::Variable["Double"],
					body: Dhall::Variable["Text"]
				),
				)
			}.freeze

			def annotate(*)