caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Yotam Barnoy <yotambarnoy@gmail.com>
To: "Paul A. Steckler" <steck@stecksoft.com>
Cc: Ocaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Default value in module
Date: Tue, 12 Sep 2017 17:21:49 -0400	[thread overview]
Message-ID: <CAN6ygOkPQaWKwHRK66rno2c1g0-+cVuFGnCfc73AzTPWdZ_E8g@mail.gmail.com> (raw)
In-Reply-To: <CAMSKV5eBE9WhE3xiKA4oBVf1Ek_4AqzkTMNaXLEM=_bmHay3Kg@mail.gmail.com>

The easiest thing to do is to create a prototype module with the value
you want, and to include that module (include Foo) in any module you
want to have that basic structure. You can even have as many prototype
modules as you want, so the system is extremely flexible.

On Tue, Sep 12, 2017 at 4:00 PM, Paul A. Steckler <steck@stecksoft.com> wrote:
> I found myself wanting to define several modules that implement a
> module type, where all the implementations but one use the same value
> of an item in the type. Essentially, I wanted a default value in the
> module type, which I can override if needed. Maybe there's a way to do
> this already.
>
> If not, the type could look like:
> --
> module type Foo =
> sig
>   val ?x : int = 42
>  end
> --
>
> and instances could be:
>
> --
> module Bar1 : Foo =
> struct
>   let x = 17
> end
>
> module Bar2 : Foo =
> struct
> end
> --
>
> Is this a reasonable idea?
>
> More precisely, I wanted to take an existing module type, add an item
> to it, and then edit just the instance with the non-default value. As
> it was, I had to edit all the instances. I could have used the class
> system to do something similar, but that would have required changing
> even more code.
>
> -- Paul
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

  parent reply	other threads:[~2017-09-12 21:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-12 20:00 Paul A. Steckler
2017-09-12 21:17 ` SP
2017-09-12 21:21 ` Yotam Barnoy [this message]
2017-09-12 21:29   ` Paul A. Steckler
2017-09-13 18:56     ` Martin Jambon
     [not found] ` <21484041-b7ed-33f0-4434-6817a82289fe@lexifi.com>
2017-09-12 21:49   ` Paul A. Steckler
2017-09-13 18:57     ` Martin Jambon

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=CAN6ygOkPQaWKwHRK66rno2c1g0-+cVuFGnCfc73AzTPWdZ_E8g@mail.gmail.com \
    --to=yotambarnoy@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=steck@stecksoft.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;
as well as URLs for NNTP newsgroup(s).