caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Gabriel Scherer <gabriel.scherer@gmail.com>
To: Gabriel Scherer <gabriel.scherer@gmail.com>,
	caml users <caml-list@inria.fr>
Subject: Re: [Caml-list] Error: The type abbreviation t is cyclic while defining submodules
Date: Fri, 10 Jun 2016 16:23:07 -0400	[thread overview]
Message-ID: <CAPFanBF-cc_XDNLN5F5MpB+0=JNcHkE8yKGkbaW6w2BMhF3EYQ@mail.gmail.com> (raw)
In-Reply-To: <20160610201840.GA2182@pl-59055.rocqadm.inria.fr>

I think the problem is rather that the Set.S signature has abstract
types "t" (for sets) and "elt" (for elements), and that you mean "with
type elt = t" here.

Note that you don't need any of the signature constraints here:

module OrderedPoints = struct
  type nonrec t = t
  let compare = compare
end
module PointSet = Set.Make(OrderedPoints)

works. On the other hand, (module OrderedPoints : Set.OrderedType =
...) is not good as it makes OrderedPoints.t an abstract type, and
thus you cannot use it from client code afterwards.

Finally, if you want your code to type-check under an older OCaml
version without nonrec, you can work around the lack of it with
synonyms

type u = t
module OrderedPoints = struct
  type t = u
  let compare = compare
end

On Fri, Jun 10, 2016 at 4:18 PM, Sébastien Hinderer
<Sebastien.Hinderer@inria.fr> wrote:
> Gabriel Scherer (2016/06/10 16:05 -0400):
>> P.S.: Note that "nonrec" is only in definitions (struct .. end) and
>> signatures (sig .. end), not in equations such as "with type t = t"
>> which are a different construct, interpreted recursively -- not the
>> best choice for consistency, but well.
>
> So to make an equality between two types public one has to first
> introduce a signature, right?
>
> Now the code looks like this:
>
> type t = float * float
>
> let compare = Pervasives.compare
>
> (* Other functions on points *)
>
> module OrderedPoints : Set.OrderedType with type t = t = struct
>   type nonrec t = t
>   let compare = compare
> end
>
> module PointSet (* : Set.S with type t = t *) = Set.Make(OrderedPoints)
>
> Note the commented bit in the last line, when it is uncommented it does
> indeed not work.
>
> Thanks,
>
> Sébastien.

  reply	other threads:[~2016-06-10 20:23 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-10 20:00 Sébastien Hinderer
2016-06-10 20:03 ` Gabriel Scherer
2016-06-10 20:05   ` Gabriel Scherer
2016-06-10 20:17     ` Gabriel Scherer
2016-06-10 20:18     ` Sébastien Hinderer
2016-06-10 20:23       ` Gabriel Scherer [this message]
2016-06-10 20:29         ` Sébastien Hinderer
2016-06-10 20:10   ` Sébastien Hinderer

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='CAPFanBF-cc_XDNLN5F5MpB+0=JNcHkE8yKGkbaW6w2BMhF3EYQ@mail.gmail.com' \
    --to=gabriel.scherer@gmail.com \
    --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).