caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
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 14:39:19 +0200	[thread overview]
Message-ID: <CAPFanBG1Xfi6RWzKjMu1nHOaup7zf=vCcYwpzRgz3LgFmRqYow@mail.gmail.com> (raw)
In-Reply-To: <5184FDB0.30406@inria.fr>

I did not need such form of self-reference to build converter from a
set to another.

(* binary converter functor *)
module SetConverter (S1 : Set.S) (S2 : Set.S) : sig
  val convert : (S1.elt -> S2.elt) -> (S1.t -> S2.t)
end = struct
  let convert f s1 =
    S1.fold (fun e s2 -> S2.add (f e) s2) s1 S2.empty
end

(* currified version as a Set.S overlay *)
module SetWithConverter (E : Set.OrderedType) : sig
  include Set.S
  module Converter (S2 : Set.S) : sig
    val convert : (elt -> S2.elt) -> (t -> S2.t)
  end
end = struct
  module S1 = Set.Make(E)
  include S1
  module Converter (S2:Set.S) = SetConverter(S1)(S2)
end


On Sat, May 4, 2013 at 2:23 PM, 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
>
> Is there a way to define such a module type in ocaml, and if not, is there a
> theoretical reason for this not being possible?
>
> Thanks,
> Michael Lienhardt
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs

  reply	other threads:[~2013-05-04 12:40 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 [this message]
2013-05-04 12:47 ` Jacques Garrigue
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='CAPFanBG1Xfi6RWzKjMu1nHOaup7zf=vCcYwpzRgz3LgFmRqYow@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --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).