caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Kaustuv Chaudhuri <kaustuv.chaudhuri@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] Defining a type and a module type recursively
Date: Sat, 28 Aug 2010 21:31:43 +0200	[thread overview]
Message-ID: <AANLkTikn8sKr7azKP7n_xpE0pygicfiJ1Fc_fBQefCDs@mail.gmail.com> (raw)
In-Reply-To: <AANLkTikyThjPQHnrJyLjbAxPsyjHoPVr1_+gtE+v0U3Z@mail.gmail.com>

On Sat, Aug 28, 2010 at 10:30 AM, Daniel Bünzli
<daniel.buenzli@erratique.ch> wrote:
> Is it possible to define a type and a module type recursively ?

Technically, you can use recusive modules to encode all kinds of
recursive type definitions. Here, for example, is your case:

    module rec M : sig
      type 'a t = 'a * (module N.T)
    end = struct
      type 'a t = 'a * (module N.T)
    end

    and N : sig
      module type T = sig
        type s = S of int M.t
      end
    end = struct
      module type T = sig
        type s = S of int M.t
      end
    end

    type 'a t = 'a M.t
    module type T = N.T

It's pretty ugly. Please only use such patterns if you have solid
reasons not to go with something simpler.

-- Kaustuv


      reply	other threads:[~2010-08-28 19:34 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-08-28  8:30 Daniel Bünzli
2010-08-28 19:31 ` Kaustuv Chaudhuri [this message]

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=AANLkTikn8sKr7azKP7n_xpE0pygicfiJ1Fc_fBQefCDs@mail.gmail.com \
    --to=kaustuv.chaudhuri@inria.fr \
    --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).