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.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 9FE89BC0A for ; Mon, 21 May 2007 17:01:54 +0200 (CEST) Received: from atlas.informatik.uni-freiburg.de (atlas.informatik.uni-freiburg.de [132.230.150.3]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id l4LF1raD030287 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Mon, 21 May 2007 17:01:54 +0200 Received: from imap1.informatik.uni-freiburg.de ([132.230.166.231]) by atlas.informatik.uni-freiburg.de with esmtp (Exim 4.66) (envelope-from ) id 1Hq9OT-0002DR-DM for caml-list@yquem.inria.fr; Mon, 21 May 2007 17:01:53 +0200 Received: from [132.230.166.125] (manuka.informatik.uni-freiburg.de [132.230.166.125]) by imap1.informatik.uni-freiburg.de (8.13.6/8.12.11) with ESMTP id l4LF1rOh022447 for ; Mon, 21 May 2007 17:01:53 +0200 (MEST) Message-ID: <4651B460.60408@informatik.uni-freiburg.de> Date: Mon, 21 May 2007 17:01:52 +0200 From: Phillip Heidegger User-Agent: Thunderbird 1.5.0.10 (X11/20070221) MIME-Version: 1.0 To: caml-list@yquem.inria.fr Subject: a question about recursiv type defintions and functors like Set.Make? Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Organization: Universitaet Freiburg, Institut f. Informatik X-Miltered: at concorde with ID 4651B461.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; functors:01 functor:01 recursion:01 struct:01 struct:01 ocaml:01 functor:01 recursive:01 ocaml:01 sig:01 val:01 val:01 bool:01 bool:01 recursive:01 Hi, I have a question about using the set functor. I need a type like: CODE1: type a = BaseCase of string | BSet of b set | ASet of a set and b = BaseCaseB of string | ASetB of a set In my first implementation I used instead of sets lists and write some functions to manipulate the values of type a and b. But now I need a faster representation for the sets, and I try to use the module "Set". But I didn't find a way using it because of the recursion in the type definition. I would like to write something like: CODE2: type a = BaseCase of string | BSet of BSet.t | ASet of ASet.t and b = BaseCaseB of string | ASetB of ASet.t and module ASet = Set.Make(struct type a let compare x y = ...end) and module BSet = Set.Make(struct type b let compare x y = ...end) (of cause this is not valid OCaml Code, but I hope it helps to understand, what I would like to do). This code did not work because I used the type ASet.t in the definition of a, and the type a in the functor call of ASet. Because modules are not recursive in OCaml, I'm not able to write code like this I think. Now my next approach was not to use the Set module, but change the code of this module, so I get a module with polymorph signature: CODE3: module Set : sig type 'a t val empty : 'a t val is_empty : 'a t -> bool val mem : ('a -> 'a -> int) -> 'a -> 'a t -> bool .... (* nearly all functions need a method compare like mem *) end I can write my type as I desired in CODE1, but I have to pass to all functions, every time I used the set, the compare Function as a parameter. For example: if (mem cmpTypeA element aSet) then ...... Is there a better way to implement this set Module? Is there a way to use the Set functor code? Is there a way to get recursiv moduls in OCaml? How should I solve my problem, if I have recursive modules. If it's possible to solve my problem without using recursive modules, what should I do? greetings, Phillip