[m-dev.] Re: Visual vs total arity clash example [fwd]

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Jan 29 11:27:33 AEDT 2000


On 28-Jan-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> > Hmm, let's see what foldl2 looks like with vars and call-site 
> > annotation in Ralph's New Syntax:
> > 
> > :- pred foldl2(pred(T) + var(x, y), list(T)) + var(x, y).
> > 
> > foldl2(P, Xs) + var(x, y) -->>
> > 	(
> > 		Xs = []
> > 	;
> > 		Xs = [H | T],
> > 		P(H) + var(x, y),
> > 		fold2(P, T) + var(x, y)
> > 	).
> 
> Thinking more about this, I think we might be able to do away
> with the `htype' etc. declarations.  Consider:
> 
> :- pred foldl2(pred(T) + var(x, y), list(T)) + var(x, y).
> :- mode foldl2(pred(in) + var((in,out),(in,out)) is det, in) +
> 	var((in,out),(in,out)) is det.
> 
> would have the obvious expansion:
> 
> :- pred foldl2(pred(T, TX, TX, TY, TY), list(T), TX, TX, TY, TY).
> :- mode foldl2(pred(in, in, out, in, out) is det,
> 	in, out, in, out)	is det.

But if mutable x has type `io__state', then that expansion would
be wrong.  It's OK in this case, because foldl2 can be polymorphic,
but there are many predicates, e.g. io__write_string, which can't
be polymorphic; how would the expansion work in that case?

Similarly, if the code for that predicate happened to contain

	$x = $y

then that expansion would be wrong too.
So I don't think it works in enough cases to be worthwhile,
even as a special case of the notation that you discuss below:

> Actually, we should constrain the types of some var args
> ...  var(x:TX, y:TY).

OK, that would work.  But then you have to annotate the
types at every point, whereas the advantage of `:- htype'
declarations is that you only need to specify the type
in one spot.

-- 
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.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list