~singpolyma/dhall-ruby

2b749ff90d33e9793d068526f1358272808fc373 — Stephen Paul Weber 1 year, 2 months ago 2b40654
Add Natural/subtract
3 files changed, 23 insertions(+), 1 deletions(-)

M dhall-lang
M lib/dhall/builtins.rb
M lib/dhall/typecheck.rb
M dhall-lang => dhall-lang +1 -1
@@ 1,1 1,1 @@
Subproject commit f692f70bafa0322da5d9c4b535b2d323a9c5ac61
Subproject commit c7082d910d956bcedfdc51daae989659a2db67bd

M lib/dhall/builtins.rb => lib/dhall/builtins.rb +17 -0
@@ 98,6 98,23 @@ module Dhall
			end
		end

		class Natural_subtract < BuiltinFunction
			protected

			def uncurried_call(x, y)
				if Natural_isZero.new.call(x) === true ||
				   Natural_isZero.new.call(y) === true
					return y
				end

				unless x.is_a?(Dhall::Natural) && y.is_a?(Dhall::Natural)
					return unfill(x, y)
				end

				Dhall::Natural.new(value: [y.to_i - x.to_i, 0].max)
			end
		end

		class Natural_even < BuiltinFunction
			protected


M lib/dhall/typecheck.rb => lib/dhall/typecheck.rb +5 -0
@@ 1060,6 1060,11 @@ module Dhall
					)
				)
			),
			"Natural/subtract"  => Dhall::Forall.of_arguments(
				Builtins[:Natural],
				Builtins[:Natural],
				body: Builtins[:Natural]
			),
			"Natural/isZero"    => Dhall::Forall.of_arguments(
				Builtins[:Natural],
				body: Builtins[:Bool]