Loading ...
Sorry, an error occurred while loading the content.
 

Recursive Variants of Set

Expand Messages
  • Jacques du Preez
    Hi, Please consider my common.mli: type id = | Id of Common.Id_set.t ... module Id_set : (Set.S with type elt = id) Now my common.ml: type id = | Id of
    Message 1 of 6 , Jul 12, 2014
      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
    • Gabriel Scherer
      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
      Message 2 of 6 , Jul 12, 2014
        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 jacquesdpz@... [ocaml_beginners] <ocaml_beginners@yahoogroups.com> 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



      • Jacques du Preez
        Thank you so much Gabriel. I ll have a look at that. Thanks! ============================== Jacques du Preez Web: OpenLandscape.net EMail: jacquesdpz@gmail.com
        Message 3 of 6 , Jul 12, 2014
          Thank you so much Gabriel. I'll have a look at that. Thanks!

          ==============================
          Jacques du Preez

          Web: OpenLandscape.net
          EMail: jacquesdpz@...
          Twitter: @jacquesdp


          On Sat, Jul 12, 2014 at 5:20 PM, Gabriel Scherer gabriel.scherer@... [ocaml_beginners] <ocaml_beginners@yahoogroups.com> 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 jacquesdpz@... [ocaml_beginners] <ocaml_beginners@yahoogroups.com> 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




        • Jacques du Preez
          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
          Message 4 of 6 , Jul 14, 2014
            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: jacquesdpz@...
            Twitter: @jacquesdp


            On Sat, Jul 12, 2014 at 5:25 PM, Jacques du Preez <jacquesdpz@...> wrote:
            Thank you so much Gabriel. I'll have a look at that. Thanks!

            ==============================
            Jacques du Preez

            Web: OpenLandscape.net
            EMail: jacquesdpz@...
            Twitter: @jacquesdp


            On Sat, Jul 12, 2014 at 5:20 PM, Gabriel Scherer gabriel.scherer@... [ocaml_beginners] <ocaml_beginners@yahoogroups.com> 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 jacquesdpz@... [ocaml_beginners] <ocaml_beginners@yahoogroups.com> 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





          • Gabriel Scherer
            As the variant constructors Common and ObjStore are declared in the Identity sub-module, you should access them as Identity.Common and Identity.ObjStore: #
            Message 5 of 6 , Jul 14, 2014
              As the variant constructors Common and ObjStore are declared in the Identity sub-module, you should access them as Identity.Common and Identity.ObjStore:

              # IdSet.elements
                (List.fold_right IdSet.add
                   [Identity.Common "C"; Identity.ObjStore "OS"]
                   IdSet.empty);;
              - : IdSet.elt list = [Identity.Common "C"; Identity.ObjStore "OS"]

              It is also possible to "open" the Identity module to put its names in scope so that you don't have to prefix them. You can also (in recent-ish versions of OCaml) open a module locally using the syntaxes (let open <module> in <expression>) or (<module>.(<expression>)), for example:

              IdSet.elements
                (List.fold_right IdSet.add
                   Identity.([Common "C"; ObjStore "OS"])
                   IdSet.empty);;



              On Mon, Jul 14, 2014 at 4:51 PM, Jacques du Preez jacquesdpz@... [ocaml_beginners] <ocaml_beginners@yahoogroups.com> wrote:


              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: jacquesdpz@...
              Twitter: @jacquesdp


              On Sat, Jul 12, 2014 at 5:25 PM, Jacques du Preez <jacquesdpz@...> wrote:
              Thank you so much Gabriel. I'll have a look at that. Thanks!

              ==============================
              Jacques du Preez

              Web: OpenLandscape.net
              EMail: jacquesdpz@...
              Twitter: @jacquesdp


              On Sat, Jul 12, 2014 at 5:20 PM, Gabriel Scherer gabriel.scherer@... [ocaml_beginners] <ocaml_beginners@yahoogroups.com> 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 jacquesdpz@... [ocaml_beginners] <ocaml_beginners@yahoogroups.com> 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








            • Jacques du Preez
              Thanks Gabriel for saving me again :-) Also, I was a bit silly. In my haste, I also forgot to use List.fold_right. After reading Set s documentation carefully
              Message 6 of 6 , Jul 14, 2014
                Thanks Gabriel for saving me again :-)

                Also, I was a bit silly. In my haste, I also forgot to use List.fold_right. After reading Set's documentation carefully again, I realized I have to use: Id (IdSet.add (Common "C") IdSet.empty).

                Thank you so much,
                ==============================
                Jacques du Preez

                Web: OpenLandscape.net
                EMail: jacquesdpz@...
                Twitter: @jacquesdp


                On Mon, Jul 14, 2014 at 5:25 PM, Gabriel Scherer gabriel.scherer@... [ocaml_beginners] <ocaml_beginners@yahoogroups.com> wrote:
                 

                As the variant constructors Common and ObjStore are declared in the Identity sub-module, you should access them as Identity.Common and Identity.ObjStore:

                # IdSet.elements
                  (List.fold_right IdSet.add
                     [Identity.Common "C"; Identity.ObjStore "OS"]
                     IdSet.empty);;
                - : IdSet.elt list = [Identity.Common "C"; Identity.ObjStore "OS"]

                It is also possible to "open" the Identity module to put its names in scope so that you don't have to prefix them. You can also (in recent-ish versions of OCaml) open a module locally using the syntaxes (let open <module> in <expression>) or (<module>.(<expression>)), for example:

                IdSet.elements
                  (List.fold_right IdSet.add
                     Identity.([Common "C"; ObjStore "OS"])
                     IdSet.empty);;




                On Mon, Jul 14, 2014 at 4:51 PM, Jacques du Preez jacquesdpz@... [ocaml_beginners] <ocaml_beginners@yahoogroups.com> wrote:


                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: jacquesdpz@...
                Twitter: @jacquesdp


                On Sat, Jul 12, 2014 at 5:25 PM, Jacques du Preez <jacquesdpz@...> wrote:
                Thank you so much Gabriel. I'll have a look at that. Thanks!

                ==============================
                Jacques du Preez

                Web: OpenLandscape.net
                EMail: jacquesdpz@...
                Twitter: @jacquesdp


                On Sat, Jul 12, 2014 at 5:20 PM, Gabriel Scherer gabriel.scherer@... [ocaml_beginners] <ocaml_beginners@yahoogroups.com> 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 jacquesdpz@... [ocaml_beginners] <ocaml_beginners@yahoogroups.com> 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









              Your message has been successfully submitted and would be delivered to recipients shortly.
              »
              «