Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] Map + Set
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2004-07-25 (16:26)
From: Matt Gushee <mgushee@h...>
Subject: Re: [Caml-list] Map + Set
On Sun, Jul 25, 2004 at 04:17:55PM +0800, Martin Jambon wrote:
> I need a functional data structure that has a decent efficiency (i.e.
> not lists) and can represent `sets of named containers' so that I can
> find a container in a set, remove it from the set, update it and put it
> back into the set.
> val find : elt -> t -> elt  (* yes! *)
> Finally I just copy-pasted set.mli and and inserted a find
> function... but is there a better solution?

What I did when faced with a similar problem was:

  module MySet =
      module BaseSet = Set.Make(
      include BaseSet
      let find elt set = ...

Now of course that will only handle one data type. If you want
polymorphism, I suppose you could try something like:

  module MySet =
      module Make =
        functor(SomeMod:SOMETYPE) ->
            include Set.Make
            let find elt set = ...

Though I haven't tried the more general approach.

Matt Gushee                 When a nation follows the Way,
Englewood, Colorado, USA    Horses bear manure through           its fields;   When a nation ignores the Way,
                            Horses bear soldiers through
                                its streets.
                            --Lao Tzu (Peter Merel, trans.)

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: