* [Caml-list] Error: The type abbreviation t is cyclic while defining submodules
@ 2016-06-10 20:00 Sébastien Hinderer
2016-06-10 20:03 ` Gabriel Scherer
0 siblings, 1 reply; 8+ messages in thread
From: Sébastien Hinderer @ 2016-06-10 20:00 UTC (permalink / raw)
To: caml-list
Dear all,
Assume the following code in a file points.ml:
type t = float * float
let compare = Pervasives.compare
(* Other functions on points *)
module OrderedPoints : Set.OrderedType with type t = t = struct
type t = t
let compare = compare
end
module PointSet : Set.S with type t = t = Set.Make(OrderedPoints)
The line
type t = t
yields the above mentionned error.
Is there a way to let the compiler know that the t appearing after the
"=" sign refers to the type defined at points.ml top level?
Thanks!
Sébastien.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Error: The type abbreviation t is cyclic while defining submodules
2016-06-10 20:00 [Caml-list] Error: The type abbreviation t is cyclic while defining submodules Sébastien Hinderer
@ 2016-06-10 20:03 ` Gabriel Scherer
2016-06-10 20:05 ` Gabriel Scherer
2016-06-10 20:10 ` Sébastien Hinderer
0 siblings, 2 replies; 8+ messages in thread
From: Gabriel Scherer @ 2016-06-10 20:03 UTC (permalink / raw)
To: Sébastien Hinderer, caml users
This is
type nonrec t = t
which has been introduced in 4.02, after some years of internal usage
of (a syntax preprocessor implementing) it internally in Jane Street.
On Fri, Jun 10, 2016 at 4:00 PM, Sébastien Hinderer
<Sebastien.Hinderer@inria.fr> wrote:
> Dear all,
>
> Assume the following code in a file points.ml:
>
> type t = float * float
>
> let compare = Pervasives.compare
>
> (* Other functions on points *)
>
> module OrderedPoints : Set.OrderedType with type t = t = struct
> type t = t
> let compare = compare
> end
>
> module PointSet : Set.S with type t = t = Set.Make(OrderedPoints)
>
>
> The line
> type t = t
> yields the above mentionned error.
>
> Is there a way to let the compiler know that the t appearing after the
> "=" sign refers to the type defined at points.ml top level?
>
> Thanks!
>
> Sébastien.
>
> --
> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Error: The type abbreviation t is cyclic while defining submodules
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:10 ` Sébastien Hinderer
1 sibling, 2 replies; 8+ messages in thread
From: Gabriel Scherer @ 2016-06-10 20:05 UTC (permalink / raw)
To: Sébastien Hinderer, caml users
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.
On Fri, Jun 10, 2016 at 4:03 PM, Gabriel Scherer
<gabriel.scherer@gmail.com> wrote:
> This is
>
> type nonrec t = t
>
> which has been introduced in 4.02, after some years of internal usage
> of (a syntax preprocessor implementing) it internally in Jane Street.
>
> On Fri, Jun 10, 2016 at 4:00 PM, Sébastien Hinderer
> <Sebastien.Hinderer@inria.fr> wrote:
>> Dear all,
>>
>> Assume the following code in a file points.ml:
>>
>> type t = float * float
>>
>> let compare = Pervasives.compare
>>
>> (* Other functions on points *)
>>
>> module OrderedPoints : Set.OrderedType with type t = t = struct
>> type t = t
>> let compare = compare
>> end
>>
>> module PointSet : Set.S with type t = t = Set.Make(OrderedPoints)
>>
>>
>> The line
>> type t = t
>> yields the above mentionned error.
>>
>> Is there a way to let the compiler know that the t appearing after the
>> "=" sign refers to the type defined at points.ml top level?
>>
>> Thanks!
>>
>> Sébastien.
>>
>> --
>> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Error: The type abbreviation t is cyclic while defining submodules
2016-06-10 20:03 ` Gabriel Scherer
2016-06-10 20:05 ` Gabriel Scherer
@ 2016-06-10 20:10 ` Sébastien Hinderer
1 sibling, 0 replies; 8+ messages in thread
From: Sébastien Hinderer @ 2016-06-10 20:10 UTC (permalink / raw)
To: Gabriel Scherer; +Cc: caml users
Gabriel Scherer (2016/06/10 16:03 -0400):
> This is
>
> type nonrec t = t
>
> which has been introduced in 4.02, after some years of internal usage
> of (a syntax preprocessor implementing) it internally in Jane Street.
Thanks so much for such a prompt and helpful response, Gabriel!
Sébastien.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Error: The type abbreviation t is cyclic while defining submodules
2016-06-10 20:05 ` Gabriel Scherer
@ 2016-06-10 20:17 ` Gabriel Scherer
2016-06-10 20:18 ` Sébastien Hinderer
1 sibling, 0 replies; 8+ messages in thread
From: Gabriel Scherer @ 2016-06-10 20:17 UTC (permalink / raw)
To: Sébastien Hinderer, caml users
> not in equations such as "with type t = t"
> which are a different construct, interpreted recursively
There is a typo above, I meant to say that such type constraints are
*not* recursive, and thus do not need a nonrec construction.
On Fri, Jun 10, 2016 at 4:05 PM, Gabriel Scherer
<gabriel.scherer@gmail.com> wrote:
> 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.
>
> On Fri, Jun 10, 2016 at 4:03 PM, Gabriel Scherer
> <gabriel.scherer@gmail.com> wrote:
>> This is
>>
>> type nonrec t = t
>>
>> which has been introduced in 4.02, after some years of internal usage
>> of (a syntax preprocessor implementing) it internally in Jane Street.
>>
>> On Fri, Jun 10, 2016 at 4:00 PM, Sébastien Hinderer
>> <Sebastien.Hinderer@inria.fr> wrote:
>>> Dear all,
>>>
>>> Assume the following code in a file points.ml:
>>>
>>> type t = float * float
>>>
>>> let compare = Pervasives.compare
>>>
>>> (* Other functions on points *)
>>>
>>> module OrderedPoints : Set.OrderedType with type t = t = struct
>>> type t = t
>>> let compare = compare
>>> end
>>>
>>> module PointSet : Set.S with type t = t = Set.Make(OrderedPoints)
>>>
>>>
>>> The line
>>> type t = t
>>> yields the above mentionned error.
>>>
>>> Is there a way to let the compiler know that the t appearing after the
>>> "=" sign refers to the type defined at points.ml top level?
>>>
>>> Thanks!
>>>
>>> Sébastien.
>>>
>>> --
>>> 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
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Error: The type abbreviation t is cyclic while defining submodules
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
1 sibling, 1 reply; 8+ messages in thread
From: Sébastien Hinderer @ 2016-06-10 20:18 UTC (permalink / raw)
To: Gabriel Scherer; +Cc: caml users
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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Error: The type abbreviation t is cyclic while defining submodules
2016-06-10 20:18 ` Sébastien Hinderer
@ 2016-06-10 20:23 ` Gabriel Scherer
2016-06-10 20:29 ` Sébastien Hinderer
0 siblings, 1 reply; 8+ messages in thread
From: Gabriel Scherer @ 2016-06-10 20:23 UTC (permalink / raw)
To: Gabriel Scherer, caml users
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.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [Caml-list] Error: The type abbreviation t is cyclic while defining submodules
2016-06-10 20:23 ` Gabriel Scherer
@ 2016-06-10 20:29 ` Sébastien Hinderer
0 siblings, 0 replies; 8+ messages in thread
From: Sébastien Hinderer @ 2016-06-10 20:29 UTC (permalink / raw)
To: caml-list
Thanks again Gabriel! Everything seems clear now!
Sébastien.
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2016-06-10 20:29 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-06-10 20:00 [Caml-list] Error: The type abbreviation t is cyclic while defining submodules 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
2016-06-10 20:29 ` Sébastien Hinderer
2016-06-10 20:10 ` Sébastien Hinderer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox