[mercury-users] Re: State variable problem

Ralph Becket rafe at cs.mu.OZ.AU
Wed May 31 11:29:44 AEST 2006


Nicholas Nethercote, Wednesday, 31 May 2006:
> On Wed, 31 May 2006, Ralph Becket wrote:
> 
> >>Oh, I see:  you're not allowed to use !Errs in a function application.
> >
> >Yes, state vars in function applications == very odd.
> 
> Why is that?  The manual says 
> (http://www.cs.mu.oz.au/research/mercury/information/doc-latest/mercury_ref/State-variables.html#State%20variables):
> 
>   !X may not appear as an argument in a function application since this
>   would not make sense given the usual interpretation of state variables and
>   functions.
> 
> which doesn't explain much.  In Mercury I think of predicates and functions 
> being basically the same except for syntax (cue horrified gasps from more 
> knowledgeable members of the audience), but I guess there's something 
> deeper than that here.

I used to think the same way, but I've been convinced otherwise.  The
main thing is that with functions it is natural to assume referential
transparency.  That is, when I see

	X = f(g(Y), g(Y))

I assume that means the same as

	Z = g(Y),
	X = f(Z, Z)

But I don't assume referential transparency with predicates: that is, I
*don't* see

	p(Y, Z1),
	p(Y, Z2),
	q(Z1, Z2, X)

and think it means the same as

	p(Y, Z1),
	Z2 = Z1,
	q(Z1, Z2, X)

Using state variable pairs in functions confounds my expectations.

> Also, it would be nice if the error message was a little clearer when you 
> try to do this.

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