From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=AWL,SPF_FAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 6EADFBBAF for ; Fri, 31 Jul 2009 18:23:47 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AjwCAES3ckpQW+UCe2dsb2JhbACaHAEBFiQEuSKEGAWBSg X-IronPort-AV: E=Sophos;i="4.43,303,1246831200"; d="scan'208";a="44205318" Received: from main.gmane.org (HELO ciao.gmane.org) ([80.91.229.2]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/AES256-SHA; 31 Jul 2009 18:23:47 +0200 Received: from list by ciao.gmane.org with local (Exim 4.43) id 1MWutM-0001HR-Sr for caml-list@inria.fr; Fri, 31 Jul 2009 16:23:36 +0000 Received: from elehack.net ([216.243.177.100]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 31 Jul 2009 16:23:36 +0000 Received: from michael+ocaml by elehack.net with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Fri, 31 Jul 2009 16:23:36 +0000 X-Injected-Via-Gmane: http://gmane.org/ To: caml-list@inria.fr From: Michael Ekstrand Subject: Re: Cartesian product Date: Fri, 31 Jul 2009 11:23:24 -0500 Message-ID: References: <8401c38a0907301056x470687aah94b2b1295c6d1068@mail.gmail.com> <8401c38a0907301454q1c60ac2frf8b0ab9027a6475d@mail.gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: elehack.net User-Agent: Mozilla-Thunderbird 2.0.0.19 (X11/20090103) In-Reply-To: <8401c38a0907301454q1c60ac2frf8b0ab9027a6475d@mail.gmail.com> Sender: news X-Spam: no; 0.00; ocaml:01 functor:01 functor:01 struct:01 arbitrarily:01 type-safe:01 wrote:01 typing:01 arbitrary:02 construct:02 module:03 module:03 static:03 let:03 let:03 Ligia Nistor wrote: > 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. That would be possible (use a type of Type.t list), but the resulting set types would have a static typing hole: you would not be guaranteed that all elements would have the same length. Another way to do it would be to have a Product functor, like so: module Product = functor (T1: Set.ORDERED_TYPE) -> functor (T2: Set.ORDERED_TYPE) -> struct type t = T1.t * T2.t let compare (a1,b1) (a2,b2) = let r = T1.compare a1 a2 in if r = 0 then T2.compare b1 b2 else r end Then you can create a 2-ary product set type: module Set2 = Set.Make(Product(Type)(Type)) and build further sets by constructing products of products: module Set3 = Set.Make(Product(Product(Type))(Type))) That would allow you to construct arbitrarily high-dimensional product set types that still remain type-safe. - Michael