From: Goswin von Brederlow <goswin-v-b@web.de>
To: Peter Hawkins <hawkinsp@cs.stanford.edu>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Extending modules and signatures
Date: Fri, 17 Apr 2009 23:36:35 +0200 [thread overview]
Message-ID: <87ocuv2c9o.fsf@frosties.localdomain> (raw)
In-Reply-To: <b0b348900904171351q656b0d21j63ce39b5646f1a3a@mail.gmail.com> (Peter Hawkins's message of "Fri, 17 Apr 2009 13:51:45 -0700")
Peter Hawkins <hawkinsp@cs.stanford.edu> writes:
> Hi...
>
> I have a quick question. I want to extend the List module with various
> functions that I want that aren't present in the standard library,
> much as the Batteries ExtList library does.
>
> I might write the following code in "mylibrary.ml":
> module MyList = struct
> include List
> let foo x = ... code here
> let bar y = ... code here
> end
>
> That's ok so far, but now suppose I want to write a "mylibrary.mli"
> interface file corresponding to "mylibrary.ml". Ideally I'd write
> something like this in "mylibrary.mli":
> module MyList : sig
> include List (* unknown module type List *)
> val foo : ...
> val bar : ...
> end
>
> Unfortunately I can't include "List" here since it is a structure, not
> a signature. I don't think there is a way to say "include the
> signature associated with List".
>
> I can think of three solutions:
> a) Copy the complete signature of List into MyList. This is a bad idea
> since the List module might change in the future. This is what the
> Batteries ExtList module does.
> b) Alter the List module to define a signature, say List.S, in
> addition to its other contents. I can't easily do this since I didn't
> write the List module.
> c) Don't write a .mli file at all.
>
> Are there any other alternatives?
Something like :
module MyList = struct
include List
module M : sig val foo : int -> unit end = struct
let foo x = ()
let bar y = y
end
include M
end
and no .mli file. The module M is there to alow you to give (or hide)
the signature of just your extra functions.
> Cheers,
> Peter
MfG
Goswin
next prev parent reply other threads:[~2009-04-17 21:36 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-04-17 20:51 Peter Hawkins
2009-04-17 21:36 ` Goswin von Brederlow [this message]
2009-04-18 5:47 ` [Caml-list] " Ashish Agarwal
2009-04-18 14:20 ` Martin Jambon
2009-04-19 21:36 ` Ashish Agarwal
2009-04-19 21:53 ` Jon Harrop
2009-04-20 5:17 ` Goswin von Brederlow
2009-04-20 0:06 ` Martin Jambon
2009-04-20 5:23 ` Goswin von Brederlow
2009-04-20 11:55 ` Martin Jambon
2009-04-21 16:01 ` Ashish Agarwal
2009-04-17 21:30 Dario Teixeira
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=87ocuv2c9o.fsf@frosties.localdomain \
--to=goswin-v-b@web.de \
--cc=caml-list@yquem.inria.fr \
--cc=hawkinsp@cs.stanford.edu \
/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