You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 6703 Reporter:@alainfrisch Status: acknowledged (set by @damiendoligez on 2015-01-08T22:50:01Z) Resolution: open Priority: normal Severity: feature Target version: later Category: typing Tags: patch Related to:#6688#6698 Monitored by:@gasche@diml@ygrek@hcarty
Bug description
It would be convenient to use "val" declarations in structures to specify the type of value defined by a "let binding" immediately after:
val f : int -> int
val g : int -> int
let rec f x = ...
and g x = ...
Values defined by the let-binding and mentioned in immediately preceding val declarations will be matched against those declarations. Those not mentioned will use their inferred type (i.e. this cannot be used to hide declarations).
Such sequences of val declarations must be followed immediately by a let binding.
This is a conservative proposal: a more ambitious one could be to use "val" declarations to support forward definitions. We can do that later (or not).
I've attached a patch which implements the feature. Note that val declarations are not used to type-check the value definitions, only to check the inferred types. In particular, this form cannot be used as the explicit annotation required for polymorphic recursion. There is also a problem with location on error report: while the locations of the definition and the declaration are reported as "sub-location" in the error message, the main location points to the entire file.
With the attached patch, "val x : ... let x = ...." behaves as "include (struct let x = ... end : sig val x : ... end)" (but identifiers not listed in val declarations are not hidden). In particular, the declaration can be less general than the definition.
If we want to be able to use declarations as an alternative way to specify the annotation required for polymorphic recursion, this interpretation wouldn't work anymore. The declaration would have to be taken into account while type-checking the definition.
If we want to be able to use declarations as an alternative way to specify the annotation required for polymorphic recursion, this interpretation wouldn't work anymore.
This issue has been open one year with no activity. Consequently, it is being marked with the "stale" label. What this means is that the issue will be automatically closed in 30 days unless more comments are added or the "stale" label is removed. Comments that provide new information on the issue are especially welcome: is it still reproducible? did it appear in other contexts? how critical is it? etc.
Original bug ID: 6703
Reporter: @alainfrisch
Status: acknowledged (set by @damiendoligez on 2015-01-08T22:50:01Z)
Resolution: open
Priority: normal
Severity: feature
Target version: later
Category: typing
Tags: patch
Related to: #6688 #6698
Monitored by: @gasche @diml @ygrek @hcarty
Bug description
It would be convenient to use "val" declarations in structures to specify the type of value defined by a "let binding" immediately after:
val f : int -> int
val g : int -> int
let rec f x = ...
and g x = ...
Values defined by the let-binding and mentioned in immediately preceding val declarations will be matched against those declarations. Those not mentioned will use their inferred type (i.e. this cannot be used to hide declarations).
Such sequences of val declarations must be followed immediately by a let binding.
Notes:
"val" declarations are already accepted syntactically as structure items (see Accept value declarations as structure items #6688), but currently always rejected by the type-checker.
This is a conservative proposal: a more ambitious one could be to use "val" declarations to support forward definitions. We can do that later (or not).
Using "val" declarations makes it possible, and natural, to attach attributes such as @@ocaml.deprecated to inferred signature items (allow @@ocaml.deprecated on structure items? #6698).
I've attached a patch which implements the feature. Note that val declarations are not used to type-check the value definitions, only to check the inferred types. In particular, this form cannot be used as the explicit annotation required for polymorphic recursion. There is also a problem with location on error report: while the locations of the definition and the declaration are reported as "sub-location" in the error message, the main location points to the entire file.
File attachments
The text was updated successfully, but these errors were encountered: