[mercury-users] List instantiation question

Peter Hawkins hawkinsp at cs.stanford.edu
Thu Mar 2 17:33:01 AEDT 2006


On Mar 1, 2006, at 9:51 PM, Ralph Becket wrote:
>> Is there some list mode that I am not aware of that solves this  
>> issue?
> Not really.
> Whenever someone tries to do something Prologesque like this it's
> usually an efficiency hack.

Actually, my personal desire for partial instantiation comes when  
trying to be excessively tricky. My most recent example was when  
trying to write a grammar that can be used for both parsing and  
generation. The idea was something like this (and I thought it was  
one of my more evil ideas for some time =) ):

:- type stream ---> input(...) ; output(...).
:- inst input_stream ---> input(...).
:- inst output_stream ---> output(...).

:- type thing ---> foo(int) ; bar(string).
:- inst partial_thing ---> foo(free) ; bar(free).

:- pred read_or_write_thing(thing, stream, stream).
:- mode read_or_write_thing(out, in(input_stream), out(input_stream))  
is det.
:- mode read_or_write_thing(in, in(output_stream), out 
(output_stream)) is det.

read_or_write_thing(X) -->
		{ X = foo(A) },
		{ X = bar(B) },

:- pred read_or_write_which_of_foo_or_bar(thing, stream, stream).
:- mode read_or_write_which_of_foo_or_bar(in, in(output_stream), out 
(output_stream)) is det.
:- mode read_or_write_which_of_foo_or_bar(out(partial_thing), in 
(input_stream), out(input_stream)) is det.

Unfortunately you can't actually write the predicate  
read_or_write_which_of_foo_or_bar/3 because it would have to output a  
partially instantiated structure as its first argument in the input  

Ok, maybe this is a gross abuse of the mode system. But it would have  
saved me duplicating my grammar for input and output.

I'll go back to my hole now.

mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe

More information about the users mailing list