Dependent insts

Thomas Charles Conway conway at hydra.cs.mu.oz.au
Wed Mar 10 16:07:30 AEDT 1999


Hi

Consider the following program:

:- module dependent.

:- interface.

:- import_module io.

:- pred main(io__state, io__state).
:- mode main(di, uo) is det.

:- implementation.

:- import_module string.

:- type (T/U) ---> (T/U).

:- inst isspecial = bound((
		(bound("builtin") / bound("int"))
	;	(bound("builtin") / bound("float"))
	;	(bound("builtin") / bound("character"))
	;	(bound("builtin") / bound("string"))
	;	(bound("std_util") / bound("univ"))
	)).


main -->
	read_word(Res0),
	read_word(Res1),
	(
		{ Res0 = ok(Chars0) },
		{ string__from_char_list(Chars0, Str0) },
		{ Res1 = ok(Chars1) },
		{ string__from_char_list(Chars1, Str1) }
	->
		{ Thingy = Str0/Str1 },
		(
			{ isspecial(Thingy) }
		->
			write_special(Thingy)
		;
			write_string("no.\n")
		),
		main
	;
		[]
	).

:- pred isspecial(string/string).
:- mode isspecial(ground -> isspecial) is semidet.

isspecial("builtin" / "int").
isspecial("builtin" / "float").
isspecial("builtin" / "character").
isspecial("builtin" / "string").
isspecial("std_util" / "univ").

:- pred write_special(string/string, io__state, io__state).
:- mode write_special(in(isspecial), di, uo) is det.

write_special("builtin" / "int") -->
	write_string("int\n").
write_special("builtin" / "float") -->
	write_string("float\n").
write_special("builtin" / "character") -->
	write_string("char\n").
write_special("builtin" / "string") -->
	write_string("string\n").
write_special("std_util" / "univ") -->
	write_string("univ\n").

I would expect it to behave in the following way:

$ ./dependent
builtin int
int
builtin string
string
^C
$

Where, in fact it actually behaves in the following way:
$ ./dependent
builtin int
char
builtin string
char
^C
$

Oh, and it produced the following error file:

dependent.m:060: Warning: this disjunct will never have any solutions.
dependent.m:062: Warning: this disjunct will never have any solutions.
dependent.m:066: Warning: this disjunct will never have any solutions.
dependent.m:068: Warning: this disjunct will never have any solutions.

I guess the compiler did get it half right. It did admit that
write_special was det, but as for the rest....

It seems that for the compiler to distinguish alternatives in an
inst, they must be discriminated by their top level functor. Is
there any *technical* reason that the program above shouldn't behave
as desired? I appreciate there may be a significant amount of
implementation effort required to handle this kind of case.

Allowing this sort of thing makes it easier to get deterministic
switches on groups of items. Yes, there are workarounds, I know.

Thomas
-- 
Thomas Conway <conway at cs.mu.oz.au> )O+
To a killer whale, otters are like hairy popcorn -- Paul Dayton




More information about the developers mailing list