caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Signature substitution and type parameters
@ 2013-08-12  7:45 Gabriel Kerneis
  2013-08-12  9:57 ` Raphaël Proust
  2013-08-12 10:20 ` Jeremy Yallop
  0 siblings, 2 replies; 4+ messages in thread
From: Gabriel Kerneis @ 2013-08-12  7:45 UTC (permalink / raw)
  To: caml-list

Dear all,

Is there a concise way to instanciate a module containing a parametric
type for a particular value of this type parameter?

  module type Poly = sig type 'a t val f : 'a t -> 'a t end ;;
  module type Mono = sig type t val f : t -> t end ;;

  module PolyM : Poly = struct type 'a t let f x = x end ;;

The following works but is tedious when Poly contains many functions
instead of only one:

  module MonoM : Mono = struct
    open PolyM
    type t = int PolyM.t
    let f = PolyM.f
  end ;;

My other attempts so far:

  # module MonoM : (Mono with type t := int PolyM.t) = PolyM ;;
  Error: Only type constructors with identical parameters can be
  substituted.

  # module MonoM : (Mono with type t = int PolyM.t) = PolyM ;;
  Error: Signature mismatch:
    Modules do not match:
      sig type 'a t = 'a PolyM.t val f : 'a t -> 'a t end
    is not included in
      sig type t = int PolyM.t val f : t -> t end
    Type declarations do not match:
      type 'a t = 'a PolyM.t
    is not included in
      type t = int PolyM.t
    They have different arities. 

Is this a fundamental limitation of the typechecker, which would
otherwise lead to unsafe behaviour?

  Note: The initial motivation for doing this was to use Jean-Christophe
  Filliâtre's Hset as a drop-in replacement for OCaml's Set in one of my
  programs, without having to add type parameters all over the place.
  https://www.lri.fr/~filliatr/ftp/ocaml/ds/hset.mli.html

Kind regards,
-- 
Gabriel

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

end of thread, other threads:[~2013-08-12 12:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-12  7:45 [Caml-list] Signature substitution and type parameters Gabriel Kerneis
2013-08-12  9:57 ` Raphaël Proust
2013-08-12 10:20 ` Jeremy Yallop
2013-08-12 12:25   ` Gabriel Kerneis

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