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

How to extend both a module and its submodule

Expand Messages
  • code17
    Hi there, I wonder how I can extend both a module F and its sub-module S (which is then referred to as F.S) I know I can include a module and extend with my
    Message 1 of 2 , Mar 4, 2005
      Hi there,

      I wonder how I can extend both a module F and its sub-module S (which is then
      referred to as F.S)

      I know I can "include" a module and extend with my additional
      definitions. However, I found if I include F in my FExt, then I can do nothing
      to the FExt.S included consequently. I tried to declare a new S in FExt and
      hopefully to add my new FExt.S functions there, and "name conflict" error is then
      reported. (BTW, I want to keep the sub-module names S, so I can use this
      extended version both as a standalone library and a substitution version
      overriding the original one, just as some extension libraries in ExtLib do.)

      I don't know how to handle this. I figured a extremely ugly way: First extend F
      as FTmp inside which a sub-module FTmp.STmp extending F.S, write specific
      interface file for FTmp which export only FTmp.STmp not FTmp.S; Second, declare
      a new F module which includes FTmp, it also has a sub-module F.S including
      FTmp.STmp, write specific interface for the new F which exports only the
      sub-module F.S not F.STmp. After these two times of transform, we are done. I
      haven't tried it, since it never seems to be a smart way.

      Do you have any suggestions? Or, at this moment, things should be just like
      this?

      BTW, actually, I need to extend Bigarray and its sub-module Genarray with some
      functionalities I frequently use. If there is already someone did similar job
      during his(her) work, please tell me. I would be glad to know that. :)

      code17
    • Richard Jones
      The problem is that include F isn t really a way of extending modules. What include F does is to import all the symbols in F into the current namespace,
      Message 2 of 2 , Mar 4, 2005
        The problem is that "include F" isn't really a way of extending
        modules. What "include F" does is to import all the symbols in F into
        the current namespace, *and* export them from the current namespace.
        (It's the latter thing which makes "include F" different from "open F").

        It doesn't matter if the symbols in F are values or happen to be
        modules (like F.S).

        Could your "extended" BigArrayExt.GenArray be called instead
        BigArrayExt.GenArrayExt? If so, then it's should be simple enough to
        do.

        Or you could copy the code ...

        Rich.

        --
        Richard Jones, CTO Merjis Ltd.
        Merjis - web marketing and technology - http://merjis.com
        Team Notepad - intranets and extranets for business - http://team-notepad.com
      Your message has been successfully submitted and would be delivered to recipients shortly.