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

Peter Driscoll peter_driscoll at bigpond.com
Thu Apr 4 10:28:41 AEST 2002


One thing I don't understand is, if the compiler can check and see if I get
the modes wrong, why can't it work out the modes for me?  The same question
applies also for determinism.  The compiler works out the types where you
have type variables.

Regards

Peter Driscoll

-----Original Message-----
From: owner-mercury-users at cs.mu.OZ.AU
[mailto:owner-mercury-users at cs.mu.OZ.AU]On Behalf Of Ralph Becket
Sent: Thursday, 4 April 2002 9:39 AM
To: mercury-users at cs.mu.OZ.AU
Subject: Re: [mercury-users] Is DCG really appropriate, even for the
things it does well?


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

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