[mercury-users] Syntax question: Creating a list of higher order predicates?

David Overton dmo at cs.mu.OZ.AU
Fri Dec 12 09:12:11 AEDT 2003


On Thu, Dec 11, 2003 at 02:35:45PM +0100, obo at ruk.cuni.cz wrote:
> Hi.
> 
> I'd like to create a list of predicates. Something like:
> 
> :- type plotter == pred(string, io, io).
> :- inst plotter == (pred(in, di, uo) is det).
> :- type plotters == list(plotter).
> :- inst plotters ????

:- inst plotters == list_skel(plotter).

The inst list_skel/1 is defined in the `list' module in the library as

:- inst list_skel(I) ---> [] ; [I | list_skel(I)].

> 
> I'm not really sure how to write the instatiation of plotters -- I wish to
> fill the list very simply, still at the compile time, such as
> [write_string(String), write_int(15)].

Assuming those are the write_string/3 and write_int/3 from the `io'
module, the above declarations won't work.  You probably want

:- type plotter == pred(io, io).
:- inst plotter == (pred(di, uo) is det).

> 
> But how do I then declare the mode for the predicate cons:
> 
> :- pred cons(list(plotter), indent, io, io).
> 
> % :- mode cons(in, in, di, uo) is det.
> % This mode decl. is definitely wrong.

:- mode cons(in(plotters), in, di, uo) is det.


David
-- 
David Overton                  Uni of Melbourne     +61 3 8344 1354
dmo at cs.mu.oz.au                Monash Uni (Clayton) +61 3 9905 9373
http://www.cs.mu.oz.au/~dmo    Mobile Phone         +61 4 0337 4393
--------------------------------------------------------------------------
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