| Newsgroups |
gmane.comp.lang.ocaml.beginners |
| Message-ID |
<CAMBKu=fjtmR+gj20TN5+i4enAOBtYc6HTvCQ1XBqgXcbApttrQ@mail.gmail.com> |
Hi,
Okay, so I got the recursive module right, and a variant that's a set of
the variant type itself - Id of IdSet.t:
module rec Identity :
sig
type id = | Id of IdSet.t
| Common of string
| ObjStore of string
end
= struct
type id = | Id of IdSet.t
| Common of string
| ObjStore of string
end
and IdSet: Set.S with type elt = Identity.id
= Set.Make(
struct
type t = Identity.id
let compare = Pervasives.compare
end)
But for the life of me I can seem to use the "Id" variant type. How on
earth do I create "Id" with a set of type id's other variances?
In other words, if I wanted to use the variant Common for instance, I'll
say: Common "some str value". How do I do this for Id, as in something
like:
Id IdSet.add ([Common "C"; ObjStore "OS"] IdSet.empty)
However, I've tried numerous variations of the above statement, and it's
either complaining about a syntax error, or that type Common.Identity.id
doesn't have a constructor - depending on where I place the parenthesis.
Help!?
Thank you,
==============================
Jacques du Preez
Web: OpenLandscape.net
EMail: [email protected]
Twitter: @jacquesdp
On Sat, Jul 12, 2014 at 5:25 PM, Jacques du Preez <[email protected]>
wrote:
> Thank you so much Gabriel. I'll have a look at that. Thanks!
>
> ==============================
> Jacques du Preez
>
> Web: OpenLandscape.net
> EMail: [email protected]
> Twitter: @jacquesdp
>
>
> On Sat, Jul 12, 2014 at 5:20 PM, Gabriel Scherer [email protected]
> [ocaml_beginners] <[email protected]> wrote:
>
>>
>>
>> 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
>>>
>>>
>>>
>>
>>
>
>