Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007453OCamltoplevelpublic2017-01-07 16:552017-02-23 17:03
Reporteryallop 
Assigned Todim 
PrioritynormalSeverityminorReproducibilityhave not tried
StatusassignedResolutionopen 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0007453: Broken toplevel printing for types and modules (rec/nonrec not shown correctly)
DescriptionRecursive type definitions are incorrectly displayed as explicitly non-recursive definitions:

    # #show list;;
    type nonrec 'a list = [] | (::) of 'a * 'a list
    # type t = T of t;;
    type t = T of t
    # #show t;;
    type nonrec t = T of t

And recursive module definitions are incorrectly displayed as implicitly non-recursive definitions:

    # module rec M : sig type t val x : M.t end = struct type t = int let x = 0 end;;
    module rec M : sig type t val x : M.t end
    # #show_module M;;
    module M : sig type t val x : M.t end

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0017162)
dim (developer)
2017-01-13 19:26

I had a look at this. I wrote two small functions to check if a type/module is recursive and select the rec_status field in the implementation of "show_XXX" according to this. The branch is here:

  https://github.com/diml/ocaml/tree/fix-toplevel-type-and-module-printing [^]

It seems to work, there is just a bug when calling #show_module multiple times that I haven't fixed yet.

Another approach would be to record the recursive status inside the type/module declaration, so that the output of #show matches what the user wrote. Currently you get nonrec if the type is not in fact recursive:

# type t = int;;
type t = int
# #show t;;
type nonrec t = int
(0017163)
yallop (developer)
2017-01-13 20:10

Thanks for looking at this.

I don't think that preserving what the user wrote is especially worthwhile; the important thing is that what is printed is as close to correct as possible. If it's not too difficult, I think the best scheme would be:

   * default to printing 'module' and switch to 'module rec' where the module type mentions the module name. I think this is what you've implemented already.

   * default to printing 'type' and switch to 'type nonrec' where necessary (i.e. where the type definition would mean something different if you left out the 'nonrec'). This is a bit different to your current scheme.

For actually-recursive types there's no difference between your current scheme and the proposal above. And there's no difference for types that actually need 'nonrec', either. The only difference is for non-recursive types that can be written equivalently either with or without 'nonrec', such as 'type t = int', and it's best if those are printed as simply as possible.

- Issue History
Date Modified Username Field Change
2017-01-07 16:55 yallop New Issue
2017-01-13 18:39 dim Assigned To => dim
2017-01-13 18:39 dim Status new => assigned
2017-01-13 19:26 dim Note Added: 0017162
2017-01-13 20:10 yallop Note Added: 0017163
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-02-23 17:03 doligez Category -OCaml general => toplevel


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker