[m-rev.] Converting univ values to strings

Fergus Henderson fjh at cs.mu.OZ.AU
Wed Jul 16 17:00:09 AEST 2003


On 16-Jul-2003, Ralph Becket <rafe at cs.mu.OZ.AU> wrote:
> Index: library/io.m
...
> @@ -2882,48 +2600,41 @@
>  :- mode io__write_type_desc(in, di, uo) is det.
>  
>  io__write_type_desc(TypeDesc) -->
> -	io__write_string(type_name(TypeDesc)).
> +	io__get_op_table(OpsTable),
> +	{ univ_to_string(canonicalize, OpsTable, univ(TypeDesc), String) },
> +	io__write_string(String).
>  
>  :- pred io__write_type_ctor_desc(type_ctor_desc, io__state, io__state).
>  :- mode io__write_type_ctor_desc(in, di, uo) is det.
>  
>  io__write_type_ctor_desc(TypeCtorDesc) -->
> +	io__get_op_table(OpsTable),
> +	{ univ_to_string(canonicalize, OpsTable, univ(TypeCtorDesc), String) },
> +	io__write_string(String).
>  
>  :- pred io__write_c_pointer(c_pointer, io__state, io__state).
>  :- mode io__write_c_pointer(in, di, uo) is det.
>  
> +io__write_c_pointer(C_Pointer) -->
> +	io__get_op_table(OpsTable),
> +	{ univ_to_string(canonicalize, OpsTable, univ(C_Pointer), String) },
> +	io__write_string(String).
>  
>  :- pred io__write_array(array(T), io__state, io__state).
>  :- mode io__write_array(in, di, uo) is det.
>  
>  io__write_array(Array) -->
> +	io__get_op_table(OpsTable),
> +	{ univ_to_string(canonicalize, OpsTable, univ(Array), String) },
> +	io__write_string(String).
>  
>  :- pred io__write_private_builtin_type_info(private_builtin__type_info(T)::in,
>  		io__state::di, io__state::uo) is det.
>  io__write_private_builtin_type_info(PrivateBuiltinTypeInfo) -->
> +	io__get_op_table(OpsTable),
> +	{ univ_to_string(canonicalize, OpsTable, univ(PrivateBuiltinTypeInfo),
> +		String) },
> +	io__write_string(String).

I think all of those procedures are now dead, aren't they?
Can't all that code be just deleted?

> Index: library/std_util.m
...
> +	% univ_to_string(Univ):
> +	% 	returns a canonicalized string representation of the object
> +	% 	stored in Univ using the standard Mercury operators.
> +:- func univ_to_string(univ) = string.
> +
> +	% As above, but parameterised by a table of operators.
> +	%
> +:- func univ_to_string(ops__table, univ) = string.
> +
> +	% As above, but the caller specifies what behaviour should
> +	% occur for non-canonical terms (i.e. terms where multiple
> +	% representations may compare as equal):
> +	% - `do_not_allow' will throw an exception if any subterm of
> +	%    the univ value is not canonical;
> +	% - `canonicalize' will substitute a string indicating the
> +	%    presence of a non-canonical subterm;
> +	% - `include_details_cc' will show the structure of any
> +	%    non-canonical subterms, but can only be called from a
> +	%    committed choice context.
> +	%
> +:- pred univ_to_string(deconstruct__noncanon_handling, ops__table, univ,
> +	string).
> +:- mode univ_to_string(in(do_not_allow), in, in, out) is det.
> +:- mode univ_to_string(in(canonicalize), in, in, out) is det.
> +:- mode univ_to_string(in(include_details_cc), in, in, out) is cc_multi.
> +:- mode univ_to_string(in, in, in, out) is cc_multi.
...
> Index: library/string.m
...
> +:- func string__string(T) = string.
> +%	string__string(Value)
> +%		Converts an arbitrary value to a canonicalized string
> +%		representation using the standard Mercury operator
> +%		table.

Hmm... for the variants with >= 2 arguments, wouldn't it be more natural
for the user if the interface used `T', like string__string/1, rather than
`univ', like univ_to_string/1?

Also, why provide both univ_to_string/1 and string__string/1?
If we provided only string__string/1, a user who wants
univ_to_string(Univ) can call string(univ_value(Univ)).
It doesn't seem worth complicating the library interface by
providing both of them.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list