packages feed

ychr-0.1.0.0: test/golden/negative_number_literals/negative_number_literals.chr

:- module(nnl, [t/2, neg/2, type(tags/0)]).
:- use_module(prelude).
:- chr_constraint t/2, neg/2.
:- chr_type tags ---> neg_int ; neg_float ; arith_int ; arith_flt ; diff.

% Negative literals as direct values.
t(neg_int, R)    <=> R = -42.
t(neg_float, R)  <=> R = -3.14.

% Negative literal in arithmetic (via host '-' delegation).
t(arith_int, R)  <=> R is host:'-'(-5, 3).
t(arith_flt, R)  <=> R is host:'-'(-1.5, 2.0).

% Subtraction with a negative literal RHS.
t(diff, R)       <=> R is 1 - 2.

% Prefix negation applied to a goal-supplied variable, via host '-'.
neg(X, R) <=> R is host:'-'(0, X).