[m-rev.] for review: add builtin.unsafe_cast_any_to_ground/1
Julien Fischer
juliensf at csse.unimelb.edu.au
Wed May 9 17:32:12 AEST 2007
For review by anyone.
Estimated hours taken: 0.1
Branches: main
Move G12's any_util.unsafe_cast_ground/1 function into the Mercury standard
library. (The name has changed.) Most non-trivial uses of solver types
require similar functionality so we may as well provide it in the standard
library.
library/builtin.m:
Add unsafe_cast_any_to_ground/1 as a builtin.
NEWS:
Announce the new function.
Julien.
Index: NEWS
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/NEWS,v
retrieving revision 1.457
diff -u -r1.457 NEWS
--- NEWS 1 May 2007 01:13:09 -0000 1.457
+++ NEWS 9 May 2007 07:15:13 -0000
@@ -17,6 +17,9 @@
Changes to the Mercury standard library:
+* We have added a new builtin predicate, unsafe_cast_any_to_ground/1, that
+ can be useful when manipulating polymorphic values that have inst any.
+
* Predicates and functions which create strings from lists of characters
now fail, throw an exception or return an error value if a null character
is found. Unexpected null characters in strings are a potential source of
Index: library/builtin.m
===================================================================
RCS file: /home/mercury/mercury1/repository/mercury/library/builtin.m,v
retrieving revision 1.126
diff -u -r1.126 builtin.m
--- library/builtin.m 15 Jan 2007 02:23:59 -0000 1.126
+++ library/builtin.m 9 May 2007 07:15:13 -0000
@@ -148,9 +148,8 @@
% not `unique', then the behaviour is undefined. (If you lie to the
% compiler, the compiler will get its revenge!)
%
-:- pred unsafe_promise_unique(T::in, T::uo) is det.
-
:- func unsafe_promise_unique(T::in) = (T::uo) is det.
+:- pred unsafe_promise_unique(T::in, T::uo) is det.
% A synonym for fail/0; this name is more in keeping with Mercury's
% declarative style rather than its Prolog heritage.
@@ -159,6 +158,17 @@
%-----------------------------------------------------------------------------%
+ % This function is useful for converting polymorphic non-solver type
+ % values with inst any to inst ground (the compiler recognises that inst
+ % any is equivalent to ground for non-polymorphic non-solver type values.)
+ %
+ % Do not call this on solver type values unless you are absolutely sure
+ % they are semantically ground.
+ %
+:- func unsafe_cast_any_to_ground(T::ia) = (T::out) is det.
+
+%-----------------------------------------------------------------------------%
+
% A call to the function `promise_only_solution(Pred)' constitutes a
% promise on the part of the caller that `Pred' has at most one
% solution, i.e. that `not some [X1, X2] (Pred(X1), Pred(X2), X1 \=
@@ -1109,6 +1119,29 @@
semipure_true :-
semipure private_builtin.semip.
+
+%-----------------------------------------------------------------------------%
+
+:- pragma foreign_proc("C",
+ unsafe_cast_any_to_ground(X::ia) = (Y::out),
+ [promise_pure, will_not_call_mercury, thread_safe, will_not_modify_trail],
+"
+ Y = X;
+").
+
+:- pragma foreign_proc("C#",
+ unsafe_cast_any_to_ground(X::ia) = (Y::out),
+ [promise_pure, will_not_call_mercury, thread_safe, will_not_modify_trail],
+"
+ Y = X;
+").
+
+:- pragma foreign_proc("Java",
+ unsafe_cast_any_to_ground(X::ia) = (Y::out),
+ [promise_pure, will_not_call_mercury, thread_safe, will_not_modify_trail],
+"
+ Y = X;
+").
%-----------------------------------------------------------------------------%
:- end_module builtin.
--------------------------------------------------------------------------
mercury-reviews mailing list
Post messages to: mercury-reviews at csse.unimelb.edu.au
Administrative Queries: owner-mercury-reviews at csse.unimelb.edu.au
Subscriptions: mercury-reviews-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the reviews
mailing list