univ and functor/arg
Fergus Henderson
fjh at mundook.cs.mu.OZ.AU
Thu May 1 20:15:21 AEST 1997
I wrote:
>I think the current behaviour of expand/4, functor/3, and argument/3
>for arguments of type `univ' is wrong. There is a distinction between
>the univ itself and the value stored in it (e.g. the univ itself
>always has type `univ', whereas the value stored in the univ may
>have any type). However, those predicates currently ignore this
>distinction. This can lead to incorrect behaviour, e.g. output by
>`io__write' that isn't type-correct.
But on third thoughts, maybe the current behaviour isn't so bad
after all. If you think of `univ' as conceptually defined by
:- type univ ---> univ(some [T] T).
then functor/3 for a univ should return `univ/1', and so the current
behaviour is wrong. However, if you think of `univ' as conceptually defined
by
:- type univ == some [T] T.
then the current behaviour of functor/3 etc is correct.
I'm not sure if that conceptual definition of univ as an equivalence
type really makes any sense, but pragmatically it seems to work better,
so at least for the moment I think I will stick with the existing behaviour.
Hence the following change:
library/io.m:
Delete the definition of expand_univ, just use expand instead.
cvs diff: Diffing .
Index: io.m
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/io.m,v
retrieving revision 1.119
diff -u -r1.119 io.m
--- io.m 1997/05/01 09:09:48 1.119
+++ io.m 1997/05/01 09:11:04
@@ -1413,37 +1413,19 @@
io__write_list_tail(Term) -->
(
- { expand_univ(Term, ".", _Arity, [ListHead, ListTail]) }
+ { expand(Term, ".", _Arity, [ListHead, ListTail]) }
->
io__write_string(", "),
io__write_univ(ListHead),
io__write_list_tail(ListTail)
;
- { expand_univ(Term, "[]", _Arity, []) }
+ { expand(Term, "[]", _Arity, []) }
->
[]
;
io__write_string(" | "),
io__write_univ(Term)
).
-
- % XXX expand_univ should be in std_util.m
-:- pred expand_univ(univ, string, int, list(univ)).
-:- mode expand_univ(in, out, out, out) is det.
-
-expand_univ(Univ, Name, Arity, Args) :-
- % XXX expand is currently broken; it doesn't handle
- % `univ' properly. The commented out code is what
- % we ought to have to use; instead, we can call expand
- % directly.
-/****
- ( expand(Univ, "univ", 1, [Arg]) ->
- expand(Arg, Name, Arity, Args)
- ;
- error("expand returns wrong results for type univ")
- ).
-***/
- expand(Univ, Name, Arity, Args).
:- pred io__write_term_args(list(univ), io__state, io__state).
:- mode io__write_term_args(in, di, uo) is det.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list