Re: [m-users.] Cartesian product of two sets of things.

Volker Wysk <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>
Am Montag, dem 09.10.2023 um 09:09 +0100 schrieb Sean Charles
(emacstheviking):
> My question then is, given the two loops are basically generating a
> cartesian product, is there a module function somewhere that would do that
> for me, generate a single list of all pairs? Then I could list.chunk and
> maybe produce a cleaner bit of code. I am currently also considering on
> uncommenting out the set_hit() typeclass predicate so that I can modify
> the objects in place, so instead of returning two sets of objects ID,s I'd
> be returning a new set of objects with their respective hit flags set.

I don't know if there is, but here's my version:

-----snip-----
:- pred cart_prod(set(T)::in, set(U)::in, set(pair(T, U))::out) is det.

cart_prod(Set1, Set2, Res) :-
    solutions(
        (pred((A - B)::out) is nondet :-
            set.member(A, Set1),
            set.member(B, Set2)
        ),
        Res).
-----snip-----

Cheers,
Volker
_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.