caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: "Michaël Lienhardt" <michael.lienhardt@inria.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] recursive module type
Date: Sat, 4 May 2013 21:47:17 +0900	[thread overview]
Message-ID: <492B4A0C-06A9-4B72-83E7-5DC585690EC3@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <5184FDB0.30406@inria.fr>


On 2013/05/04, at 21:23, Michaël Lienhardt <michael.lienhardt@inria.fr> wrote:

> Hello,
> 
> I would like to define some recursive module type in caml, like
> module type S = sig
> ...
> module Toto(M : S) : sig
>  ...
> end
> end
> 
> More precisely, I'd like to extend the Set module available in the ocaml distribution with a function that convert a set into another set.
> Intuitively, I came up with the following signature S, which is not accepted by ocaml (Error: Unbound module type S):
> 
>  module type S = sig
> 
>    include Set.S
> 
>    module Convert : functor(SetTarget : S) -> sig
>      val convert : (elt -> SetTarget.elt) -> t -> SetTarget.t
>    end
>  end

You first problem is syntactic.
You cannot define recursive signatures, just recursive modules.
But the signature may refer recursively to the module.
So you can attempt to write the following:

module rec M : sig
  module type S = sig  
     include Set.S
     module Convert : functor(SetTarget :M.S) -> sig          
       val convert : (elt -> SetTarget.elt) -> t -> SetTarget.t
     end
   end
end = M;;

unfortunately, this does not work:
Fatal error: exception Env.Recmodule

And this is not surprising, because this would let you indeed define
a recursive signature (i.e. a signature that unfolds infinitely).

Jacques Garrigue

  parent reply	other threads:[~2013-05-04 12:47 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-04 12:23 Michaël Lienhardt
2013-05-04 12:39 ` Gabriel Scherer
2013-05-04 12:47 ` Jacques Garrigue [this message]
2013-05-04 16:01   ` Michaël Lienhardt
2013-05-13 12:17   ` Alain Frisch

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=492B4A0C-06A9-4B72-83E7-5DC585690EC3@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=michael.lienhardt@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).