Conversation
|
Up to the couple of things I pointed out, the change does almost as advertised, the only exception being that the type I'll note that although this enable uses of the type constructors Stdlib.bool, the value constructors cannot be used in some cases, which theoretically limits what can be done without triggering warning 40 and 42 (which are enabled by default, even if I always disable them): # type bla = [] | (::) | () | None | Some | false | true;;
type bla = [] | (::) | () | None | Some | false | true
# Stdlib.[];;
- : bla = [] (* wrong: scope issue *)
# let v = Stdlib.(false);;
val v : bool = Stdlib.false (* good, except the syntax "Stdlib.false" doesn't parse *)
# if true then false else Stdlib.(false);;
- : bla = false (* wrong: type based disambiguation apparently overrides module path *)
# if true then false else v;; (* good *)
Error: This expression has type bool but an expression was expected of type
blaAnd talking about constructors, the built in constructors of sum types are now available in the stdlib, but not the ones of exceptions (Not_found, Match_failure, Out_of_memory etc). I think you'd need to do this to claim to fix MPR#6655. |
|
I'm not sure what you mean by "wrong" in some of the examples you list; do you mean that the current semantics is wrong, or that the behavior is too surprising and we should warn about it, or something else? Note that comes from the fact, I think, that Jeremy re-exports |
|
Oh well I expected []/true/false to be normal constructors. But you're saying they are not, because there is no syntax to access a prefixed version of them, and the syntax that looks like that is actually a local open, so that explains the weird scoping. |
|
Thanks for the thorough review, @sliquister. I've addressed your comments in the latest set of pushed commits. A number of tests are currently failing due to changes in type printing. I plan to wait a little while for further comments on the existing change before addressing the tests to avoid churn. |
Done.
Done. |
|
Another beneficial effect of this PR is that it solves the issue with the manual index MPR#7708 by giving an indexed path to built-in exceptions and types. |
|
One thing I hadn't commented on is: I'm not super happy about the not-real-constructors Could you maybe add a comment whenever this happen, to indicate that this is a hack to give a path in Stdlib to those constants, but similar tricks are not meant to be used in user code? |
|
Not in my book (but I would be wrong if it was, for example, documented in the language reference); I thought of this PR more as an exercise in making compromises on the implementation details that helps advanced users that do not-really-supported things. |
|
The manual has: |
|
IMHO, if If you feel like this should stay undocumented, but still want to fulfill the use case properly, you are welcome to champion the first commit in my patchset for infix constructors. :) |
|
For the record, I am rather in favor of integrating |
|
I would be happy to resurrect my patchset (or even a subset of it) if you feel the weather is more favorable. |
| stack reaches its maximal size. This often indicates infinite or | ||
| excessively deep recursion in the user’s program. (Not fully | ||
| implemented by the native-code compiler.) *) | ||
|
|
There was a problem hiding this comment.
This description is a bit weird "exception raised by bytecode runtime. Not fully implemented in native compiler". The first sentence should probably be runtime-agnostic and then, the last sentence can say that this is best-effort in the native runtime.
There was a problem hiding this comment.
Oh I realized you took the description from the manual. Well the manual is weird then, but it's probably not worth diverging.
There was a problem hiding this comment.
Currently, the manual has a dedicated chapter for built-in types and predefined exceptions. Does it make sense to keep it if they are all defined in the Stdlib? Or perhaps just pointers to reexport definitions? We should avoid text duplication is possible.
More general question: do we want to keep those predefined exceptions as part of the global scope even if Stdlib is not opened? Maintainers of stdlib alternatives might want to hide, rename or put in different sub-modules some of those exceptions. I guess that exceptions are predefined because they are required by the runtime system (and relying on OCaml code to register them is risky if the full stdlib is not linked); but perhaps one could have a syntax to refer to internal exceptions without "polluting" the global scope:
exception Stack_overflow = Stack_overflow[@@ocaml.builtin];;Do you think it is worth the trouble?
v-gb
left a comment
There was a problem hiding this comment.
The code/documentation looks good, I think the only concern is whether the warning on Failure "int_of_string" and friends is broken.
|
About the weird constructors: it's probably time to resume working on MPR#5936. Please have a look at the discussion there. |
22deed2 to
8705a09
Compare
|
@alainfrisch: I've removed the |
|
@damiendoligez You expressed somewhere else your reluctance against adding more "toplevel" declarations to |
8705a09 to
7c11ce5
Compare
This is now fixed, and I've rebased/squashed to clean up the history. I've also opened #2133 to make the
Suggestions on how best to address these failures are welcome. Some possibilities:
My preference is for |
903c886 to
1035527
Compare
|
Update: I moved |
1035527 to
1cd0f5d
Compare
alainfrisch
left a comment
There was a problem hiding this comment.
LGTM. Waiting for a few days before merging in case someone else wants to add something.
3f06285 to
190a974
Compare
Deprecate top-level functions extension_constructor / extension_name / extension_id.
190a974 to
9c71d4c
Compare
|
Thanks @yallop! |
|
The module [Unit] needs to be exported in [stdlib.ml] |
It's often useful to write or generate code that refers to built-in types such as
intoroption, but it's currently inconvenient to do so in a way that avoids shadowing.This PR adds aliases in
Stdlibfor the built-in typesoption,int,bool,unit, andexn, and aliases inListandArrayfor the built-in typeslistandarray. Other built-in types (floatarray,bytes,string,float,nativeint,int32,int64,lazy_tandchar) are already aliased elsewhere in the standard library.At some point in the future there may be standard library modules for some of these types (e.g.
OptionorBool); if that happens before the next release then the corresponding aliases inStdlibcould be removed.(Fixes Mantis 5072: Absolute name for built-in types such as int, bool, ... ? and Mantis 6655: Alias built-in types and pre-defined exceptions in Pervasives.)