caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Milan Stanojević" <milanst@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] avoiding boilerplate with phantom types
Date: Fri, 9 Nov 2012 19:02:21 -0500	[thread overview]
Message-ID: <CAKR7PS_s1ENqr2i5b1Kc29m4g3i4ifyKmJrQmK=vEEzE0zJsAg@mail.gmail.com> (raw)

This is my use case.
I have a module A with type t and bunch of functions. I want to create
module B which is just a wrapper around A with a phantom type
Roughly
module A : sig
  type t
  val foo : t -> int
  val bar : t -> string
end

module B : sig
   type phantom1
   type phantom2
   type 'a t   (* or maybe even type 'a t = private A.t *)
   val foo : _ t -> int
   val bar : _ t -> string

   val validate : phantom1 t -> phantom2 t
end

I was hoping I can avoid copy-pasting declarations and that I can have
some easy way to have A and B in sync as I add or remove functions
from A.
I was able to do something for implementation B but not for interface.

B.ml
type this_name_is_not_in_scope = A.t
include (A : module type of A with type t = this_name_is_not_in_scope)

type 'a t = A.t
type phantom1
type phantom2
let validate = ....

But for interface I can't do anything unless I expose type equality
between 'a B.t and A.t (which renders phantom types useless) so I had
to list all the functions by hand.
Does anyone have a better way to do this?

The problem is that I can't say include module type of A with type t := 'a t
Why is this disallowed?

Thanks,
   Milan

             reply	other threads:[~2012-11-10  0:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-10  0:02 Milan Stanojević [this message]
2012-11-10  7:49 ` Gabriel Scherer

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='CAKR7PS_s1ENqr2i5b1Kc29m4g3i4ifyKmJrQmK=vEEzE0zJsAg@mail.gmail.com' \
    --to=milanst@gmail.com \
    --cc=caml-list@inria.fr \
    /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).