Re: Recursive Variants of Set
| Newsgroups | gmane.comp.lang.ocaml.beginners |
|---|---|
| Message-ID | <CAPFanBEVyEQMWaFbHSUnBZ8PrjaZhw55nBk1-jX=rVvTAV9k2Q@mail.gmail.com> |
It is not correct to use the name of a compilation unit (.ml{,i} files)
from within its own code: the cause of the circular dependency error here
is the use of paths of the form Common.foo.
To recursively define a type and sets over it, you should use recursive
modules. This is actually the example given in the manual for recursive
modules:
http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec220
On Sat, Jul 12, 2014 at 5:13 PM, Jacques du Preez [email protected]
[ocaml_beginners] <[email protected]> wrote:
>
>
> Hi,
>
> Please consider my common.mli:
>
> type id = | Id of Common.Id_set.t
> | Common of string
> | ObjStore of string
>
> module Id_set : (Set.S with type elt = id)
>
> Now my common.ml:
>
> type id = | Id of Common.Id_set.t
> | Common of string
> | ObjStore of string
>
> module Id_set = Set.Make(
> struct
> type t = id
> let compare = Pervasives.compare
> end)
>
> The above gives an circular build error. If I change Common.Id_set.t to
> Id_set.t, then I get an unbound module error - I'm assuming this is because
> the Id_set module declaration is after the variant declaration.
>
> What I'd like to know is, how would I change my Id variant to be of type
> "id set"? Is this possible? The problem here is that Id_set depends on
> variant id, and vice versa. How to solve this?
>
> Thanks,
>
> ==============================
> Jacques du Preez
>
> Web: OpenLandscape.net
> Twitter: @jacquesdp
>
>
>
>