caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Michaël Lienhardt" <michael.lienhardt@inria.fr>
To: caml-list@inria.fr
Subject: Re: [Caml-list] recursive module type
Date: Sat, 04 May 2013 18:01:49 +0200	[thread overview]
Message-ID: <518530ED.7040700@inria.fr> (raw)
In-Reply-To: <492B4A0C-06A9-4B72-83E7-5DC585690EC3@math.nagoya-u.ac.jp>

Thanks

I also thought about the SetConverter solution.
This is what I will use.

I was asking if such a recursive definition was possible because I have a tendency to compare the ocaml module system with Java-like objects.
 From that point of view, signatures are like tree-structured Java interfaces that can declare types, values and functions in addition to methods (functors).
While typing in object-oriented languages is recursive by default, I understand that it is not the case in ocaml because of type inference:
  annotating modules with their signatures then enable recursive modules.
Then, because signatures are types, and also have some similarities with Java interfaces, I imagined that some kind of recursion is possible.

Michael Lienhardt


Le 04/05/2013 14:47, Jacques Garrigue a écrit :
>
> 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
>


  reply	other threads:[~2013-05-04 16:01 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
2013-05-04 16:01   ` Michaël Lienhardt [this message]
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=518530ED.7040700@inria.fr \
    --to=michael.lienhardt@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).