[mercury-users] Collections of closures

Fergus Henderson fjh at cs.mu.OZ.AU
Sat Jan 8 07:12:33 AEDT 2000


On 07-Jan-2000, Ralph Becket <rbeck at microsoft.com> wrote:
> 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.
...
> So my fall back position is to play the sneaky
> tricks game, which isn't great.

True.  But quite doable.

> 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 == ???.

There's no need to define a new type.
You could use

	:- type my_wrapped_clsoure == my_closure.

but obviously if you define it like that there's no point in
having that name for it.

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

For the `wrap' operation, you can use a no-op.
The only time you need something special is with the `unwrap'
operation.

	:- func unwrap(my_closure) = my_closure.
	:- mode unwrap(in) = my_closure_out is det.

	:- pragma c_code(unwrap(X::in) = Y::my_closure_out,
		will_not_call_mercury, "Y = X;").

> This is all quite distasteful

Yes, polymorphic modes would be much nicer.

-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3        |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
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