Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Phillip Heidegger <heidegger@informatik.uni-freiburg.de>
To: caml-list@yquem.inria.fr
Subject: a question about recursiv type defintions and functors like Set.Make?
Date: Mon, 21 May 2007 17:01:52 +0200	[thread overview]
Message-ID: <4651B460.60408@informatik.uni-freiburg.de> (raw)

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


             reply	other threads:[~2007-05-21 15:01 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-21 15:01 Phillip Heidegger [this message]
2007-05-21 15:52 ` [Caml-list] " Jon Harrop
2007-05-21 16:42   ` Phillip Heidegger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4651B460.60408@informatik.uni-freiburg.de \
    --to=heidegger@informatik.uni-freiburg.de \
    --cc=caml-list@yquem.inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox