Cartesian product of two or more lists: Difference between revisions

m
(Ocaml example using fold)
Line 1,871:
let cart_prod l1 l2 =
List.fold_left (fun acc1 ele1 ->
List.fold_left (fun acc2 ele2 -> (ele1,ele2)::acc2) acc1 l1) [] ll2 ;;
 
cart_prod [1; 2; 3] ['a'; 'b'; 'c'] ;;
Anonymous user