caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Default value in module
@ 2017-09-12 20:00 Paul A. Steckler
  2017-09-12 21:17 ` SP
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Paul A. Steckler @ 2017-09-12 20:00 UTC (permalink / raw)
  To: caml-list

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-09-13 18:57 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-12 20:00 [Caml-list] Default value in module Paul A. Steckler
2017-09-12 21:17 ` SP
2017-09-12 21:21 ` Yotam Barnoy
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

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).