Thanks for the reply. This is how I thought of doing it, but in the module
TypeType, type t should be a list of types( the list has to be ref, so that
it can change its length). This way, you can do the cartesian product of an
arbitrary number of sets, not only of 2.
Ligia
On Thu, Jul 30, 2009 at
stor
du : 2009-07-30 19:56:57
À : caml-list@yquem.inria.fr
CC :
Sujet : [Caml-list] Cartesian product
Hi,
Is there an already implemented way of doing the Cartesian product of 2 sets in
OCaml? My sets are of type Set.Make(Types), where Types is a module I
On Thu, 30 Jul 2009, Ligia Nistor wrote:
Hi,
Is there an already implemented way of doing the Cartesian product of 2 sets
in OCaml? My sets are of type Set.Make(Types), where Types is a module I
have defined.
The biggest problem with implementing the cartesian product is that the
type t*t
Hello Ligia---
The following code takes cartesian products of lists:
let listListPrepend x ll = List.map (fun l -> x :: l) ll
let rec cartesianProduct = function
| aList :: listList ->
let prev = cartesianProduct listList in
List.flatten (
List.map (fun x -> listListPrepe
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
I really should provide a bit more context. It's a general implementation for
crossing [Enum.t]s. Eg.
let a = List.enum [1;2;3;4]
let b = List.enum ['a'; 'b'; 'c']
let c = cross2 a b
yields [(1,'a'); (2,'a'); (3,'a'); (4,'a'); (1,'b'); ..]
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1
Not that I know of. But you can use this general implementation. It assumes
you have Enum (from Batteries, and ExtLib before). The (~~) prefix operator
is "Obj.magic".
Peng
(* makes the cross product of the given array of enumerations *)
l
Hi,
Is there an already implemented way of doing the Cartesian product of 2 sets
in OCaml? My sets are of type Set.Make(Types), where Types is a module I
have defined.
Thanks,
Ligia
___
Caml-list mailing list. Subscription management:
http://yquem.inri