[mercury-users] field update terms

David Overton dmo at cs.mu.OZ.AU
Mon Nov 19 10:56:32 AEDT 2001


On Mon, Nov 19, 2001 at 10:11:23AM +1100, Michael Day wrote:
> 
> Hi,
> 
> If I have this:
> 
> :- type foo ---> foo(field :: int).
> 
> I can't use 'field :=' as a higher order function. But when I add this:
> 
> :- func 'field :='(foo, int) = foo.
> 
> with no body, I can. How come? Surely the compiler knows about the
> function without having to explicitly declare it again?

If you don't give a declaration for a field access/update function then
it is multi-moded and its mode is inferred at each call.  However, if
you add the declaration, the function has only the default function mode
`(in, in) = out'.

It is not possible to use a multi-moded predicate/function as a
higher-order value.  You need to use an explicit lambda expression, e.g.

	func(Foo, N) = 'field :='(Foo, N)

(which also has the default function mode).


David
-- 
David Overton      Department of Computer Science & Software Engineering
PhD Student        The University of Melbourne, Victoria 3010, Australia
+61 3 8344 9159    http://www.cs.mu.oz.au/~dmo
--------------------------------------------------------------------------
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