[mercury-users] function types + impure impurity

Dominique de Waleffe ddw at miscrit.be
Wed Mar 7 01:19:43 AEDT 2001


I wanted to define f0 as a function of  no arguments returning
something: 

:- func f0=(data::out).
f0=DS:-
	DS=mctime__current_date_string.

and wanted to store said function (unevaluated) in a data structure,

:-type data ->
       data(int)
       ; closure(func=data).

This did not work (strange messages about unknown type '='	 

I then tried to define a type:
:-type funarg == (func=data).
:-type data ->
       data(int)
       ; closure(funarg).

It did not work either same strange message.

When I made it as f1 below (added an argument, ignored), I could
:-type funarg == (func(data)=data).

So what's the syntax to use for a function of zero argument?


Then, of course I wanted to make f1 impure as it really should...

As in 
:-impure func f1(T::in)=(data::out).
f1(_)=DS:-
	DS=mctime__current_date_string.

At some spot, I build a data structure which needs to store the
function pointer in a data structure, for evaluation at a later time.

add_other_dynamic_keys(args):-
	<stuff>
	add_dico_entry(Key,def(dynamic(f1)),Dico0,Dico),
	<more stuff>

To me, there is nothing impure here since the function is not
evaluated,  however the compiler reports:

dispatcher.w:2934: In call to impure function `ndictionnaire:f1/1':
dispatcher.w:2934:   purity error: call must be in an explicit unification
dispatcher.w:2934:   which is preceded by `impure' indicator.

Then of course it thinks the caller is impure, ....

dispatcher.w:2821: In predicate `ndictionnaire:add_other_dynamic_keys/2':
dispatcher.w:2821:   purity error: predicate is impure.
dispatcher.w:2821:   It must be declared `impure' or promised pure.


Of course, the mctime__current_date_string should also have been
marked as impure, because it really is.... but since it is not,
compiler thinks (and warns that f0, f1) are pure even though declared
impure... 

D.

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