prog


Cartesian product.

6 2018-12-12 04:24

>>3
To compute the cartesian product A1x...xAn:
- if n is 0 return empty
- if n is 1 map over A1 with list
- otherwise n >= 2
-- if A1 is empty return empty
-- compute P2 as A2x...xAn
-- if P2 is empty return empty
-- combine A1 with P2 and return the result

To combine A and B, map over A with a map over B with consing A_elem with B_elem, then flatten the result with e.g. append. After this simple version works, this step can be optimized a bit.

11


VIP:

do not edit these