Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: David House <dhouse@janestreet.com>
To: Pierre-Etienne Meunier <pierreetienne.meunier@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Partial module include
Date: Fri, 21 Sep 2012 17:47:17 +0100	[thread overview]
Message-ID: <CAK=fH+jAjd+Zdjfc79vPPx41YMuHJchDQ2JLcxH59gbxjYzSog@mail.gmail.com> (raw)
In-Reply-To: <4C5580B1-5737-40ED-B7B4-83ACFFAD491B@gmail.com>

Ah, no, that cannot be done. Shadowing of modules is mysteriously
disallowed :) (I suspect there is a good reason for this, but I
confess I don't know it.)

If you say what you want to do with a bit more context, there might be
a decent workaround.

On Fri, Sep 21, 2012 at 5:43 PM, Pierre-Etienne Meunier
<pierreetienne.meunier@gmail.com> wrote:
> No, sorry, what I wanted to override was a module:
>
> module A=struct
>        let a=0
>        module B=struct let b=1 end
> end
>
> module B=struct
>        include A
>        module B=struct let b=2 end
> end
>
>
> Em 21/09/2012, às 18:41, David House escreveu:
>
>> Sure. That exact code will work just fine.
>>
>> It's a special case of "shadowing", where bindings override any
>> previous ones, for the duration of their scope. E.g.:
>>
>> let x = 5 in
>> let x = 4 in
>> (* here x is 4 *)
>>
>> also:
>>
>> let x = 5 in
>> let () =
>>  let x = 4 in
>>  printf "%d " x
>> in
>> printf "%d\n" x
>>
>> Prints "4 5", because the inner binding only has effect during the
>> time that it is in scope, and afterwards the original binding is
>> "uncovered" again.
>>
>> On Fri, Sep 21, 2012 at 5:37 PM, Pierre-Etienne Meunier
>> <pierreetienne.meunier@gmail.com> wrote:
>>> Hi,
>>>
>>> Is it possible in ocaml to redefine a part of an included module, like in the following code ?
>>>
>>> module A=struct
>>>        let a=0
>>>        let b=1
>>> end
>>>
>>> module B=struct
>>>        include A
>>>        let b=2
>>> end
>>>
>>>
>>> Thanks
>>> Pierre
>>> --
>>> Caml-list mailing list.  Subscription management and archives:
>>> https://sympa-roc.inria.fr/wws/info/caml-list
>>> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
>>> Bug reports: http://caml.inria.fr/bin/caml-bugs
>>>
>
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa-roc.inria.fr/wws/info/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>

  reply	other threads:[~2012-09-21 16:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-21 16:37 Pierre-Etienne Meunier
2012-09-21 16:41 ` David House
2012-09-21 16:43   ` Pierre-Etienne Meunier
2012-09-21 16:47     ` David House [this message]
2012-09-21 16:55     ` Markus Mottl
2012-09-21 17:47     ` Jeremy Yallop

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAK=fH+jAjd+Zdjfc79vPPx41YMuHJchDQ2JLcxH59gbxjYzSog@mail.gmail.com' \
    --to=dhouse@janestreet.com \
    --cc=caml-list@inria.fr \
    --cc=pierreetienne.meunier@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox