caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] avoiding boilerplate with phantom types
@ 2012-11-10  0:02 Milan Stanojević
  2012-11-10  7:49 ` Gabriel Scherer
  0 siblings, 1 reply; 2+ messages in thread
From: Milan Stanojević @ 2012-11-10  0:02 UTC (permalink / raw)
  To: Caml List

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

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

end of thread, other threads:[~2012-11-10  7:49 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-10  0:02 [Caml-list] avoiding boilerplate with phantom types Milan Stanojević
2012-11-10  7:49 ` Gabriel Scherer

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