[m-rev.] For review: deconstruct non-canonical terms in pretty_printer.m

Ralph Becket rafe at csse.unimelb.edu.au
Mon Oct 8 14:10:17 AEST 2007


Estimated hours taken: 1
Branches: main

library/pretty_printer.m:
	Deconstruct non-canonical terms.  We justify making this det rather
	than cc_multi by assuming that the viewer of a view of a 
	non-canonical value will give it the appropriate interpretation,
	regardless.

tests/hard_coded/test_pretty_printer.exp:
tests/hard_coded/test_pretty_printer.m:
	Update the test case.

Index: library/pretty_printer.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/pretty_printer.m,v
retrieving revision 1.6
diff -u -r1.6 pretty_printer.m
--- library/pretty_printer.m	3 Sep 2007 16:41:41 -0000	1.6
+++ library/pretty_printer.m	8 Oct 2007 04:05:09 -0000
@@ -645,7 +645,18 @@
         Doc = set_formatting_limit_correctly(!.Limit,
             Formatter(Univ, ArgTypeDescs))
       else
-        deconstruct(univ_value(Univ), canonicalize, Name, _Arity, Args),
+        % We justify this promise on the grounds that
+        % (a) observers of views of non-canonical values should give
+        % them the same denotation,
+        % (b) practically it is far more useful to see the construction
+        % of non-canonical values (e.g., when debugging programs), and
+        % (c) propagating cc_multi all the way up into the interface could
+        % make use of the pretty printer very awkward.
+        %
+        promise_equivalent_solutions [Name, Args] (
+            deconstruct(univ_value(Univ), include_details_cc,
+                Name, _Arity, Args)
+        ),
         expand_format_term(Name, Args, Doc, !Limit, CurrentPri)
     ).
 
Index: tests/hard_coded/test_pretty_printer.exp
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/test_pretty_printer.exp,v
retrieving revision 1.3
diff -u -r1.3 test_pretty_printer.exp
--- tests/hard_coded/test_pretty_printer.exp	2 Sep 2007 22:43:03 -0000	1.3
+++ tests/hard_coded/test_pretty_printer.exp	8 Oct 2007 04:06:48 -0000
@@ -9,6 +9,14 @@
 
 limit = triangular(1), max lines = 3, line width = 38
 |------------------------------------|
+non_canonical_bool(...)
+...
+...
+...
+|------------------------------------|
+
+limit = triangular(1), max lines = 3, line width = 38
+|------------------------------------|
 [...]
 |------------------------------------|
 
@@ -57,6 +65,14 @@
 
 limit = triangular(1), max lines = 3, line width = 78
 |----------------------------------------------------------------------------|
+non_canonical_bool(...)
+...
+...
+...
+|----------------------------------------------------------------------------|
+
+limit = triangular(1), max lines = 3, line width = 78
+|----------------------------------------------------------------------------|
 [...]
 |----------------------------------------------------------------------------|
 
@@ -107,6 +123,15 @@
 
 limit = triangular(1), max lines = 10, line width = 38
 |------------------------------------|
+non_canonical_bool(...)
+...
+...
+...
+
+|------------------------------------|
+
+limit = triangular(1), max lines = 10, line width = 38
+|------------------------------------|
 [...]
 |------------------------------------|
 
@@ -157,6 +182,15 @@
 
 limit = triangular(1), max lines = 10, line width = 78
 |----------------------------------------------------------------------------|
+non_canonical_bool(...)
+...
+...
+...
+
+|----------------------------------------------------------------------------|
+
+limit = triangular(1), max lines = 10, line width = 78
+|----------------------------------------------------------------------------|
 [...]
 |----------------------------------------------------------------------------|
 
@@ -205,6 +239,14 @@
 
 limit = linear(1), max lines = 3, line width = 38
 |------------------------------------|
+non_canonical_bool(...)
+...
+...
+...
+|------------------------------------|
+
+limit = linear(1), max lines = 3, line width = 38
+|------------------------------------|
 [...]
 |------------------------------------|
 
@@ -253,6 +295,14 @@
 
 limit = linear(1), max lines = 3, line width = 78
 |----------------------------------------------------------------------------|
+non_canonical_bool(...)
+...
+...
+...
+|----------------------------------------------------------------------------|
+
+limit = linear(1), max lines = 3, line width = 78
+|----------------------------------------------------------------------------|
 [...]
 |----------------------------------------------------------------------------|
 
@@ -303,6 +353,15 @@
 
 limit = linear(1), max lines = 10, line width = 38
 |------------------------------------|
+non_canonical_bool(...)
+...
+...
+...
+
+|------------------------------------|
+
+limit = linear(1), max lines = 10, line width = 38
+|------------------------------------|
 [...]
 |------------------------------------|
 
@@ -353,6 +412,15 @@
 
 limit = linear(1), max lines = 10, line width = 78
 |----------------------------------------------------------------------------|
+non_canonical_bool(...)
+...
+...
+...
+
+|----------------------------------------------------------------------------|
+
+limit = linear(1), max lines = 10, line width = 78
+|----------------------------------------------------------------------------|
 [...]
 |----------------------------------------------------------------------------|
 
@@ -401,6 +469,14 @@
 
 limit = triangular(10), max lines = 3, line width = 38
 |------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+...
+|------------------------------------|
+
+limit = triangular(10), max lines = 3, line width = 38
+|------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, ...], 
   [1, 2, 3, 4, 5, 6, 7, ...], 
   [1, 2, 3, 4, 5, 6, ...], 
@@ -461,6 +537,14 @@
 
 limit = triangular(10), max lines = 3, line width = 78
 |----------------------------------------------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+...
+|----------------------------------------------------------------------------|
+
+limit = triangular(10), max lines = 3, line width = 78
+|----------------------------------------------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, ...], [1, 2, 3, 4, 5, 6, 7, ...], 
   [1, 2, 3, 4, 5, 6, ...], [1, 2, 3, 4, 5, ...], [1, 2, 3, 4, ...], 
   [1, 2, 3, ...], [1, 2, ...], [1, ...], [...], ...]
@@ -518,6 +602,15 @@
 
 limit = triangular(10), max lines = 10, line width = 38
 |------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+non_canonical_bool(43)
+
+|------------------------------------|
+
+limit = triangular(10), max lines = 10, line width = 38
+|------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, ...], 
   [1, 2, 3, 4, 5, 6, 7, ...], 
   [1, 2, 3, 4, 5, 6, ...], 
@@ -589,6 +682,15 @@
 
 limit = triangular(10), max lines = 10, line width = 78
 |----------------------------------------------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+non_canonical_bool(43)
+
+|----------------------------------------------------------------------------|
+
+limit = triangular(10), max lines = 10, line width = 78
+|----------------------------------------------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, ...], [1, 2, 3, 4, 5, 6, 7, ...], 
   [1, 2, 3, 4, 5, 6, ...], [1, 2, 3, 4, 5, ...], [1, 2, 3, 4, ...], 
   [1, 2, 3, ...], [1, 2, ...], [1, ...], [...], ...]
@@ -644,6 +746,14 @@
 
 limit = triangular(100), max lines = 3, line width = 38
 |------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+...
+|------------------------------------|
+
+limit = triangular(100), max lines = 3, line width = 38
+|------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
@@ -713,6 +823,14 @@
 
 limit = triangular(100), max lines = 3, line width = 78
 |----------------------------------------------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+...
+|----------------------------------------------------------------------------|
+
+limit = triangular(100), max lines = 3, line width = 78
+|----------------------------------------------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
@@ -783,6 +901,15 @@
 
 limit = triangular(100), max lines = 10, line width = 38
 |------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+non_canonical_bool(43)
+
+|------------------------------------|
+
+limit = triangular(100), max lines = 10, line width = 38
+|------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
@@ -894,6 +1021,15 @@
 
 limit = triangular(100), max lines = 10, line width = 78
 |----------------------------------------------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+non_canonical_bool(43)
+
+|----------------------------------------------------------------------------|
+
+limit = triangular(100), max lines = 10, line width = 78
+|----------------------------------------------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
@@ -982,6 +1118,14 @@
 
 limit = linear(10), max lines = 3, line width = 38
 |------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+...
+|------------------------------------|
+
+limit = linear(10), max lines = 3, line width = 38
+|------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, ...], ...]
 |------------------------------------|
 
@@ -1035,6 +1179,14 @@
 
 limit = linear(10), max lines = 3, line width = 78
 |----------------------------------------------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+...
+|----------------------------------------------------------------------------|
+
+limit = linear(10), max lines = 3, line width = 78
+|----------------------------------------------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, ...], ...]
 |----------------------------------------------------------------------------|
 
@@ -1085,6 +1237,15 @@
 
 limit = linear(10), max lines = 10, line width = 38
 |------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+non_canonical_bool(43)
+
+|------------------------------------|
+
+limit = linear(10), max lines = 10, line width = 38
+|------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, ...], ...]
 |------------------------------------|
 
@@ -1140,6 +1301,15 @@
 
 limit = linear(10), max lines = 10, line width = 78
 |----------------------------------------------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+non_canonical_bool(43)
+
+|----------------------------------------------------------------------------|
+
+limit = linear(10), max lines = 10, line width = 78
+|----------------------------------------------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, ...], ...]
 |----------------------------------------------------------------------------|
 
@@ -1188,6 +1358,14 @@
 
 limit = linear(100), max lines = 3, line width = 38
 |------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+...
+|------------------------------------|
+
+limit = linear(100), max lines = 3, line width = 38
+|------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
@@ -1257,6 +1435,14 @@
 
 limit = linear(100), max lines = 3, line width = 78
 |----------------------------------------------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+...
+|----------------------------------------------------------------------------|
+
+limit = linear(100), max lines = 3, line width = 78
+|----------------------------------------------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
@@ -1327,6 +1513,15 @@
 
 limit = linear(100), max lines = 10, line width = 38
 |------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+non_canonical_bool(43)
+
+|------------------------------------|
+
+limit = linear(100), max lines = 10, line width = 38
+|------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
@@ -1438,6 +1633,15 @@
 
 limit = linear(100), max lines = 10, line width = 78
 |----------------------------------------------------------------------------|
+non_canonical_bool(0)
+non_canonical_bool(1)
+non_canonical_bool(42)
+non_canonical_bool(43)
+
+|----------------------------------------------------------------------------|
+
+limit = linear(100), max lines = 10, line width = 78
+|----------------------------------------------------------------------------|
 [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
   [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 
Index: tests/hard_coded/test_pretty_printer.m
===================================================================
RCS file: /home/mercury1/repository/tests/hard_coded/test_pretty_printer.m,v
retrieving revision 1.2
diff -u -r1.2 test_pretty_printer.m
--- tests/hard_coded/test_pretty_printer.m	2 Sep 2007 22:43:03 -0000	1.2
+++ tests/hard_coded/test_pretty_printer.m	8 Oct 2007 04:02:30 -0000
@@ -52,6 +52,10 @@
     ;       op_tree * op_tree
     ;       op_tree / op_tree.
 
+:- type non_canonical_bool
+    --->    non_canonical_bool(int)
+    where equality is non_canonical_bool_eq.
+
 
 
 main(!IO) :-
@@ -215,6 +219,12 @@
                     indent("_4_", [nl, str("four"),
                         indent("_5_", [nl, str("five")])])])])])
     ]),
+    NonCanonTest = docs([
+        format(non_canonical_bool(0)), nl,
+        format(non_canonical_bool(1)), nl,
+        format(non_canonical_bool(42)), nl,
+        format(non_canonical_bool(43)), nl
+    ]),
     (   Limit = linear(100)
     ;   Limit = linear(10)
     ;   Limit = triangular(100)
@@ -236,6 +246,7 @@
     ;   Doc = fmt_susp_seq(100)
     ;   Doc = format(Tuple)
     ;   Doc = format(Square)
+    ;   Doc = NonCanonTest
     ;   Doc = IndentTest
     ).
 
@@ -252,5 +263,17 @@
       else                     mk_op_tree(1 + N/2) / mk_op_tree(0 + N/3)
     ).
 
+
+
+:- pred non_canonical_bool_eq(non_canonical_bool::in, non_canonical_bool::in)
+        is semidet.
+
+non_canonical_bool_eq(A, B) :-
+    promise_equivalent_solutions [AX, BX] (
+        A = non_canonical_bool(AX),
+        B = non_canonical_bool(BX)
+    ),
+    AX /\ 1 = BX /\ 1.
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
--------------------------------------------------------------------------
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