<div class="gmail_quote">On 20 April 2012 23:33, Julien Fischer <span dir="ltr"><<a href="mailto:juliensf@csse.unimelb.edu.au">juliensf@csse.unimelb.edu.au</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im"> :- module test.</div>
:- interface.<br>
:- import_module io.<br>
:- pred main(io::di, io::uo) is det.<br>
:- implementation.<br>
:- import_module decimal2.<br>
:- import_module bool, integer.<br>
<br>
main(!IO) :-<br>
Context1 = make_context(integer(30), round_floor, signal(no, no)),<br>
Context2 = make_context(integer(40), round_up, signal(no, no)),<br>
X = to_number(Context1, "1000000"),<br>
Y = to_number(Context2, "2900000"),<br>
Z = X `add` Y,<br>
io.write_string(to_scientific_<u></u>string(Z), !IO),<br>
<a href="http://io.nl" target="_blank">io.nl</a>(!IO).<br>
<br>
Attempting to compile the above will result in the following compilation<br>
error:<br>
<br>
Making Mercury/cs/test.c<br>
test.m:013: In clause for predicate `main'/2:<br>
test.m:013: in unification of variable `Z'<br>
test.m:013: and term `add(X, Y)':<br>
test.m:013: type error in argument(s) of functor `add/2'.<br>
test.m:013: Argument 1 (X) has type `(some [C] decimal2.decimal(C))',<br>
test.m:013: expected type was `decimal2.decimal(C)';<br>
test.m:013: argument 2 (Y) has type `(some [C] decimal2.decimal(C))',<br>
test.m:013: expected type was `decimal2.decimal(C)'.<br>
** Error making `Mercury/cs/test.c'.<br></blockquote><div><br></div>OK, thanks, Julien. That's looking like a very promising line of inquiry. Adding the context to the creation of a number was the line I was going to originally investigate but I was concerned at the need for run-time checking. Your solution eliminates that problem for me.<br>
<br></div>-- <br>"Perhaps people don't believe this, but throughout all of the discussions of entering China our focus has really been what's best for the Chinese people. It's not been about our revenue or profit or whatnot."<br>
--Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.<br>