[m-dev.] HO List args: fold and unfold

Ralph Becket rafe at cs.mu.OZ.AU
Wed Mar 15 15:26:47 AEDT 2006


Hi Doug,

here's an explanation:

	% The power set of the empty set is the set containing the empty
	% set.
	%
power_set([])       = [[]].

	% The power set of the non-empty set [X | Xs] is the union of
	% - the power set of Xs and
	% - the power set of Xs with X inserted into each subset.
	%
power_set([X | Xs]) = 
    foldr(func(S, SS) = [S, [X | S] | SS], power_set(Xs), []).

-- Ralph
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list