caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jeremy Yallop <yallop@gmail.com>
To: Gabriel Kerneis <gabriel@kerneis.info>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Signature substitution and type parameters
Date: Mon, 12 Aug 2013 11:20:17 +0100	[thread overview]
Message-ID: <CAAxsn=GzCM=9ZmvaQj+iZkmGy=ba6hJfQ+p4DuRpne96Bhv6og@mail.gmail.com> (raw)
In-Reply-To: <20130812074545.GA4646@kerneis.info>

On 12 August 2013 08:45, Gabriel Kerneis <gabriel@kerneis.info> wrote:
> 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 ;;

If you use 'include' instead of 'let' it generalizes nicely to the
many-function case:

  module MonoM : Mono = struct
    type t = int PolyM.t
    include (PolyM : Mono with type t := t)
  end

A slight variation makes it possible to achieve a similar effect
without using the Mono signature:

  type _ s = int PolyM.t
  module MonoM = struct
    type t = unit s
    include (PolyM : Poly with type 'a t := 'a s)
  end

Your other approach can be made to work, too.  The key is to define a
type alias with no parameters (type t = int PolyM.t), then use
destructive substitution (:=).

  parent reply	other threads:[~2013-08-12 10:21 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-12  7:45 Gabriel Kerneis
2013-08-12  9:57 ` Raphaël Proust
2013-08-12 10:20 ` Jeremy Yallop [this message]
2013-08-12 12:25   ` Gabriel Kerneis

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='CAAxsn=GzCM=9ZmvaQj+iZkmGy=ba6hJfQ+p4DuRpne96Bhv6og@mail.gmail.com' \
    --to=yallop@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=gabriel@kerneis.info \
    /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).