[m-dev.] 0.13 release: op/3 syntax
doug.auclair at logicaltypes.com
doug.auclair at logicaltypes.com
Thu Mar 2 06:29:55 AEDT 2006
Dear all planning the Mercury 0.13 release,
Please put in the modifications I've posted to allow op/3
declarations. I use it
in code that I deploy, and it would save me a good deal of time not having to
repatch the release and recompile the compiler, as I have been
doing for each ROTD.
Thank you.
Sincerely,
Doug Auclair
P.S. To address Julien's earlier question. op/3 declarations are visible
to /nested/ sub-modules, but not to /separate/ sub-modules. This
is exactly the
behavior of the declaration I was looking for, and what makes the
most sense to
me.
Attached: files demonstrating op/3 declaration extent to nested, but not
separate, sub-modules (when the predicate definition in bar.m was uncommented,
the compiler failed out, /properly/ not recognizing the
'divided_by' operator).
----- file: test_div.m -------------------------
:- module test_div.
% synopsis: Uses the 'div' op
% author: Douglas M. Auclair (DMA)
% date: March 1, 2006, Ash Wednesday
:- interface.
:- import_module io.
:- module foo.
:- interface.
:- pred print_div(float::in, float::in, io::di, io::uo) is det.
:- end_module foo.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module divu, test_div.foo, list, string.
:- op(400, yfx, divided_by).
:- module foo.
:- implementation.
:- import_module list, string.
print_div(A, B) -->
format("%f divided_by %f = %f\n", [f(A), f(B), f(A divided_by B)]).
:- end_module foo.
:- import_module bar.
main --> print_div(5.0, 3.0),
{ identity_transform(5, X) },
format("Hey, i(5) is %d\n", [i(X)]).
----- file: divu.m -------------------------
:- module divu.
% synopsis: Defines the 'divided_by' op
% author: Douglas M. Auclair (DMA)
% date: March 1, 2006, Ash Wednesday
:- interface.
:- func divided_by(float, float) = float.
:- implementation.
:- import_module float.
:- op(400, yfx, divided_by).
A divided_by B = C :- C = A / B.
----- file: bar.m -------------------------
:- module bar.
% synopsis: A separate sub-module of test_div ... it does NOT see
% the 'divided_by' operator declared in test_div.
% author: Douglas M. Auclair (DMA)
% date: March 1, 2006, Ash Wednesday.
:- interface.
:- pred identity_transform(int::in, int::out) is det.
% :- pred should_not_work_with_divided_by_op(float::in, float::in,
% float::out) is det.
:- implementation.
identity_transform(X, X).
% should_not_work_with_divided_by_op(A, B, C) :- C = A divided_by B.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to: mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions: mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------
More information about the developers
mailing list