Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wishlist: Support for constant values in recursive modules #4471

Closed
vicuna opened this issue Dec 30, 2007 · 1 comment
Closed

Wishlist: Support for constant values in recursive modules #4471

vicuna opened this issue Dec 30, 2007 · 1 comment

Comments

@vicuna
Copy link

vicuna commented Dec 30, 2007

Original bug ID: 4471
Reporter: furr
Status: acknowledged (set by @damiendoligez on 2008-01-10T10:46:12Z)
Resolution: open
Priority: normal
Severity: feature
Version: 3.10.0
Category: language features
Monitored by: @gasche @jberdine "Julien Signoles" @hcarty @yakobowski

Bug description

The constraint on recursive module signatures to only contain function typed values is quite restrictive. Presumably, this is because initialization of these values would be difficult in the general case.

Examining my own uses of recursive modules, a significant improvement would be if constants were considered "safe", which could be accomplished with a kind of "value restriction" for modules. This solution would be nice because it is both already familiar to the seasoned OCaml programmer (from polymorphism) and would subsume the check for function values.

@xavierleroy
Copy link
Contributor

11 years later, I'm not sure what has changed in OCaml's recursive modules, but signatures of recursively-defined modules can contain values that are not functions, and definitions by constants are supported (or expressions that don't get into a recursive cycle, more generally). Here are some examples in OCaml 4.07:

# module rec A : sig val x:int end = struct let x = 42 end;;
module rec A : sig val x : int end
# module rec A : sig val x:int end = struct let x = 42 end
  and B : sig val y:int end = struct let y = A.x end;;
module rec A : sig val x : int end
and B : sig val y : int end
# module rec A : sig val x:int end = struct let x = B.y end
  and B : sig val y:int end = struct let y = 42 end;;
module rec A : sig val x : int end
and B : sig val y : int end
# module rec A : sig val x:int end = struct let x = B.y + 1 end
  and B : sig val y:int end = struct let y = A.x * 2 end;;
Error: Cannot safely evaluate the definition of the following cycle
       of recursively-defined modules: A -> B -> A.
       There are no safe modules in this cycle (see manual section 8.4)

Let's just close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants