[mercury-users] Idea for another handy convention (preds, this time).

Thomas Conway conway at cs.mu.OZ.AU
Thu Jul 27 08:31:53 AEST 2000


On Thu, Jul 27, 2000 at 02:10:39AM EST, Ralph Becket wrote:
> I would like to propose a similar default for preds, namely
> that a predicate
> 
> :- pred p(A, B, C).
> 
> lacking a mode declaration is assumed to have the conventional
> (in most other languages) mode of
> 
> :- mode p(in, in, in) is semidet.
> 
> This would also do away with the need for excess verbiage in
> many predicate lambdas, for example:
> 
> 	Evens = list__filter((pred(X) :- X mod 2 = 0), Xs).
> 

Actually, I'd like to go further than that and have a syntax for
pred expressions that is analagous to the kind of thing we've been
talking about for defining pred types. Here is an example of why:
in my XML parser, I use a "monadic" style and have lots of instances
of the expression:
	(pred(_::in, di, uo) is det -->
	...
	)

Here is an example:

:- pred doctypedecl(pstate(_), pstate(dtd)).
:- mode doctypedecl(in, out) is det.

doctypedecl -->
    lit("<!DOCTYPE")		    then (pred(_::in, pdi, puo) is det -->
    s				    then (pred(_::in, pdi, puo) is det -->
    name			    then (pred(Root::in, pdi, puo) is det -->
    opt(snd(s and externalID))	    then (pred(_Name::in, pdi, puo) is det -->
    opt(s)			    then (pred(_::in, pdi, puo) is det -->
    opt(fst(snd(lit1('[') and star(yes(markupdecl) or no(s)))
    	and (lit1(']') and opt(s))))
				    then (pred(MStuff::in, pdi, puo) is det -->
    lit1(('>'))			    then (pred(_::in, pdi, puo) is det -->
    { initDTD(Root, DTD0) },
    {
    	MStuff = yes(MarkupDecls0),
	filterOpt(MarkupDecls0, MarkupDecls1),
	filterOpt(MarkupDecls1, MarkupDecls),
	makeDTD(MarkupDecls, DTD0, DTD)
    ;
        MStuff = no,
	DTD = DTD0
    },
    return(DTD)
    ))))))).

Note that then/4 is one of my parser combinators.


It'd be nice to be able to have "shortcut" pred expressions something
like:

:- pred_exprn cont = pred(in, pdi, puo) is det.

and then write

doctypedecl -->
    lit("<!DOCTYPE")		    then (cont(_) -->
    s				    then (cont(_) -->
    name			    then (cont(Root) -->
    ...

What would be even better is to have an operator somewhere in the grammar
that I could use instead of "then" so I didn't need all the jolly
parentheses (LISP anyone?)

Of course an even better alternative would be to have mode inference
do the job for me so that I could write:

doctypedecl -->
    lit("<!DOCTYPE")		    then (pred(_) -->
    s				    then (pred(_) -->
    name			    then (pred(Root) -->
    ...

and have the analysis do the rest.
Maybe this will become more feasible with constraint-based mode
analysis. Dave? Peter?

-- 
 Thomas Conway )O+     Every sword has two edges.
     Mercurian            <conway at cs.mu.oz.au>
--------------------------------------------------------------------------
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