|Anonymous | Login | Signup for a new account||2018-06-24 15:16 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0007453||OCaml||toplevel||public||2017-01-07 16:55||2017-11-29 14:03|
|Priority||normal||Severity||minor||Reproducibility||have not tried|
|Target Version||Fixed in Version|
|Summary||0007453: Broken toplevel printing for types and modules (rec/nonrec not shown correctly)|
|Description||Recursive 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
|Tags||No tags attached.|
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:
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
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.
Is there something blocking this?
Had a bit of a problem explaining this to students...
> default to printing 'type' and switch to 'type nonrec' where necessary
> best if those are printed as simply as possible
|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|
|2017-11-29 14:03||voglerr||Note Added: 0018720|
|Copyright © 2000 - 2011 MantisBT Group|