[mercury-users] Maths and contexts.
Michael Richter
ttmrichter at gmail.com
Sat Apr 21 01:46:04 AEST 2012
On 20 April 2012 23:33, Julien Fischer <juliensf at csse.unimelb.edu.au> wrote:
> :- module test.
> :- interface.
> :- import_module io.
> :- pred main(io::di, io::uo) is det.
> :- implementation.
> :- import_module decimal2.
> :- import_module bool, integer.
>
> main(!IO) :-
> Context1 = make_context(integer(30), round_floor, signal(no, no)),
> Context2 = make_context(integer(40), round_up, signal(no, no)),
> X = to_number(Context1, "1000000"),
> Y = to_number(Context2, "2900000"),
> Z = X `add` Y,
> io.write_string(to_scientific_**string(Z), !IO),
> io.nl(!IO).
>
> Attempting to compile the above will result in the following compilation
> error:
>
> Making Mercury/cs/test.c
> test.m:013: In clause for predicate `main'/2:
> test.m:013: in unification of variable `Z'
> test.m:013: and term `add(X, Y)':
> test.m:013: type error in argument(s) of functor `add/2'.
> test.m:013: Argument 1 (X) has type `(some [C] decimal2.decimal(C))',
> test.m:013: expected type was `decimal2.decimal(C)';
> test.m:013: argument 2 (Y) has type `(some [C] decimal2.decimal(C))',
> test.m:013: expected type was `decimal2.decimal(C)'.
> ** Error making `Mercury/cs/test.c'.
>
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.
--
"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."
--Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20120420/835fceb2/attachment.html>
More information about the users
mailing list