Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007320OCamltypingpublic2016-08-05 15:572017-04-14 16:46
Assigned To 
PlatformOSOS Version
Product Version 
Target VersionlaterFixed in Version 
Summary0007320: Relaxing the value restriction some more
DescriptionRelaxing the value restriction some more

If I write this:
# let f =
  let now = ref 0 in
  fun () -> now, ref []
val f : unit -> int ref * '_a list ref = <fun>

the type f is not generalized. But I don't name the intermediate value:

# let f =
  ref 0;
  fun () -> ref 0, ref []
val f : unit -> int ref * 'a list ref = <fun>

or I name it at toplevel:
# let now = ref 0
  let f = fun () -> now, ref []
val f : unit -> int ref * 'a list ref = <fun>

then the type is generalized.

It would be nice if, when I want to write something like the first snippet, I didn't have to write something like the third snippet instead, to work around the value restriction.

I think [let x = e1 in e2] should be generalized by saying:
- if e1 is non-expansive, then generalize the type of the whole expression
- otherwise, go down recursively in e2 to try to generalize it (the level mechanism would prevent generalization of the variables shared with the type of e1)

ie when an expression is not non-expansive, instead of giving up on generalizing it, try to generalize the non-expansive parts of it instead.

This would make all 3 examples behave the same.
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
There are no notes attached to this issue.

- Issue History
Date Modified Username Field Change
2016-08-05 15:57 sliquister New Issue
2016-09-07 16:51 shinwell Target Version => later
2017-02-23 16:45 doligez Category OCaml typing => typing
2017-04-14 16:46 doligez Status new => acknowledged

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker