[mercury-users] Collections of closures

Ralph Becket rbeck at microsoft.com
Fri Jan 7 20:44:28 AEDT 2000


I think I've been bitten by the mode system again.
What I want to do is have a mapping from keys to
(lists of) closures.  Unfortunately, because we don't
have parametric modes (this would be a great bit of
research for someone to get into!), I have to wrap
up my closures somehow if I want to use e.g. the
standard map ADT to store them.

My first thought was to use the univ interface, but
this also suffers from the mode problem: you can't
turn anything containing a closure into a univ
because univ/1 only takes arguments with mode in
or di, neither of which are applicable to higher
order objects.

So my fall back position is to play the sneaky
tricks game, which isn't great.  The idea here is
to have something like the following:

:- type my_closure == pred(...).
:- mode my_closure_in = in(pred(...) is semidet).
:- mode my_closure_out = out(pred(...) is semidet).

	% What should ??? be?
	%
:- type my_wrapped_closure == ???.

:- func wrap(my_closure) = my_wrapped_closure.
:- mode wrap(my_closure_in) = out is det.

:- pragma c_code(wrap(X::my_closure_in) = Y::out,
	will_not_call_mercury, "Y = X;").

and vice versa for unwrapping closures.  This is all
quite distasteful, so my question is what is the best
way to go about solving this problem?  I suppose I
could avoid using higher order code at all by
implementing an interpreter for a little language,
but I'd really rather avoid doing that if at all
possible.

Cheers,

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