[mercury-users] Is DCG really appropriate, even for the things it does well?

Ralph Becket rafe at cs.mu.OZ.AU
Thu Apr 4 09:39:15 AEST 2002


Fergus Henderson, Wednesday,  3 April 2002:
> 
> Actually the list__append/3 predicate has several modes.
> The function versions of list__append in the standard library don't --
> I'm not sure why, exactly.

For ease of higher order programming.  Most HO code is functional in
nature and it's very nice not to have to clutter up your code with mode
annotations in this case.  If you want the other modes, it's really no
harder to use the predicate version which, to my mind, also highlights
the fact that you intend a non-functional mode.

For example, I can write

	Xs = foldr((++), Yss, [])

using the uni-moded function (++)/2, but to get the compiler to accept
the equivalent predicate-based expression I have to add a lambda to
specify which mode I mean:

	foldr(
		(pred(Ys::in, Xs0::in, Xs::out) is det :- append(Xs0, Xs, Ys)),
		Yss,
		[],
		Xs
	)

because append/3 has multiple modes.

Simon Taylor recently added `with_inst` which might make things a bit
easier in that one should probably be able to write

	foldr(append `with_inst` (pred(in, in, out) is det), Yss, [], Xs)

although I don't think this particular form of mode declaration is
supported yet (Simon could tell us.)

- Ralph
--------------------------------------------------------------------------
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