-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Improve stdlib support for int
#2011
Conversation
I recognize I may be in the minority, but I really prefer when the default functions return |
Appveyor timedout. |
I would like to move on this PR. It seems no one has a strong objection about the module's functionality and existence. A contentious point though might be 1. here again the choice is between:
While I favour 1. full This PR deprecates the |
One reason I can think of for not doing this is that it will keep the modules |
821ab58
to
05e8c1b
Compare
I have rebased this PR to resolve the conflicts. At the same time:
|
If being able to share a common interface with Int32/Int64/... (e.g. to support algorithms abstracted over those modules) is not a goal, the rationale for exposing e.g. If being able the share a common (sub-)interface is a goal, then it's indeed unfortunate that the One possibility, which I don't necessarily fully believe in myself, but might be worth discussing would be to add [EDIT: forgot the |
That's my impression aswell and the reason why I would still like to otherwise maximize similarity with the other integer modules and hence include |
I'm unconvinced by I'm intrigued by the potential of an eventual total regularization of |
Indeed, X.print was just be to have some symmetry with X.parse. Ok, let's leave the discussion around X.parse for later. |
05e8c1b
to
d7eb0ff
Compare
I think we should strive for the largest reasonable common subset of operations between all of the integer modules (like Base does with As an example, the next version of Flambda makes extensive use of parameterisation over modules representing various kinds of numbers. As it happens, |
I agree that I would highly prefer all the |
I think it's better if we entice people to not use raising variants and the best way of doing is to not provide them. I could do 1. (see above) to make the thing more regular but I personally don't find that to be a great name (it should have been |
I didn't advise a name on purpose (I also think |
The raising ones are already irregular, see for example I'm personally rather against this both because we have an opportunity to give the good signal here and because I can see people switching from |
I'm not sure I understand. One of the reason some alternative standard libraries are used is because of their very high degree of internal consistency. You are making it worse for the stdlib here. If you want to go forward with removing all the raising variants, and I'm sure many people agree, I propose you make a patch for that, instead of doing that change in various semi-related PRs. Personally, my opinion would be to add |
It raises
Frankly, is it that bad ?
I think this misses the point somehow. This PR introduces new functionality, I'm just avoiding in this new functionality a mode of operation that we consider we should move away from. I acknowledge it introduces irregularity, I personally don't see it as a big deal. If others also think strongly about this then I think the current Regarding removing the raising variants I was actually on that track (but I don't think it's necessarily something to be done in a single PR), but somehow the discussion about deprecation and its outcome stopped me on the way. |
I wouldn't support removing existing stdlib functions or changing their types, but personally I'm ok with @dbuenzli's choice of having a more modern type for the more modern versions of |
That's fair. I don't know about others, but I do think having regular APIs is a Very Big Deal. So yes, please do the name change, either to That being said, I also disagree that raising variants should never be used. |
(Also, to play the devil's advocate, |
The current implementation of int_of_string_opt is: let int_of_string_opt s =
(* TODO: provide this directly as a non-raising primitive. *)
try Some (int_of_string s)
with Failure _ -> None Perhaps it's actually best to leave it like that. A clever inliner could then optimize: match int_of_string_opt s with
| Some x -> ...
| None -> ... into: match int_of_string s with
| x -> ...
| Failure _-> ... (Can flambda do that?) |
I actually had the plan to work on this after these things are in. So if you really think it's not worth it please say. |
So it may be time to sum up a little bit the larger picture on these
A few random comments of mine.
|
Come on, @dbuenzli, the handling of stdlib PRs is frustrating (for everyone), but your last message is rude to @alainfrisch, which is neither pleasant nor productive. It's a shitty job to be handling stdlib changes for reasons exemplified in this PR, and most people (myself included!) decided to not apply for it. @alainfrisch is currently the most active in processing stdlib proposals (with @nojb), and it's a bit sad that you would alienate him. Hacking on the stdlib sucks, and we all know it, because there are many competing choices and often no clear "better choice" to agree on (in absence of a better choice, doing nothing is often the only reasonable-looking option). (Syntax discussions are often like that, except for really good proposals like |
I apologize to @alainfrisch for it. |
I can't quite believe that it is now proposed to add these modules without the Bear in mind that unless you're writing a library from scratch, having already written such a library before with all the pitfalls and potential inconsistencies already in your head, then there is always going to be imperfection. Yes, we should have policies about breaking backwards compatibility; yes, we should have good refactoring tools; and yes, older function signatures should be updated so that everything is consistent. However blocking the addition of new, useful functions that have standard, discoverable names and just slightly different type signatures because we haven't yet solved those problems seems the wrong decision to me. Many users probably won't even notice these minor inconsistencies on a large scale---it will be a minor irritation now and then. The only real question to my mind that needed to be answered here is what the new standard interface for the functions in question should be (it would seem wrong to add new functions with old signatures, especially if such signatures are problematic in some way as the ones in question potentially are). That seems like it could have been worked out rather than kicking it into the long grass. |
(Ok, unsubscribe is not enough, since explicit @-mentions re-subscribe automatically.)
It's really not like this is blocking the addition of new useful stuff: all suggest features are already part of the Sdtlib and The decision of switching to option-returning variants pervasively in the Stdlib, for all conversion and lookup functions, is a topic on its own, rather independent of the addition of Int and much less consensual. |
I suppose you mean yourself, by camping on your position and refusing to add the basic Let's not play silly games @dbuenzli . Don't paint me as the bad guy here, we all have our pet-peeve but at least I recognized the value in yours and I was ready to compromise. I still think |
@Drup It has been pointed out that there are good reasons for preferring a standard name, also, though. Did you mean " |
@mshinwell As my previous messages on the matter should make clear, I'm not against the option returning at all. But either you do it properly (by changing everything and breaking compat) or you do it differently (by adding an extra function with that api, like |
Please I was not alone. Moreover you said you were willing to compromise but you never responded with any good argument to the concern of introducing a Anyways that discussion is over for me. I only commented the function since I did spend sometime on improving the doc string on |
I do think people tend to associate a name - especially a simple one - with a given type signature template. Remembering that So since we all basically agree that we like option-returning functions and dislike exception-based ones, why don't we incorporate |
I agree with that too, so these should be the default. Occasionally, functions raising exceptions are convenient and a suffix |
The problem with your proposal is that it doesn't entice people to upgrade and it's also quite heavy both in terms of maintenance and build obfuscation ( I think the only sane approach for the Maybe what this discussion failed at to point out is that that there are 1) different kind of inconsistencies and 2) these have different properties, from harmless to harmful and 3) that the same holds for consistencies. The inconsistency that I tried to introduce maybe felt embarrassing to some but it was not harmful from a programming perspective (amusingly the end-result is as embarrassing now). Software is never perfect, I'm routinely dissatisfied with designs I started from scratch and thought to be the ultimate one when I created them. Errors are and will still be made even in new interfaces that are being introduced now. Asking for perfection, especially in a project like the OCaml stdlib is just aiming to eventually do nothing and perpetuate our dissatisfaction with the stdlib. I think that all or nothing attitudes like that (I'm pointing the attitude not the person) will make it difficult to make significant progress on the stdlib in the future. Gradual improvement with a vision and end-user onboarding is the only solution in my opinion. |
As I see it, there is no maintenance — this solution is for existing packages in the repo to compile with the newer compilers. I did not mean to do this for new packages submitted to the repo (which can adjust their build systems). |
I meant maintenance around providing the compatibility layer. Also it may not always be possible to provide one (e.g. when new language features/primitives are introduced).
That's precisely what I think should be avoided. When you move the compilers and break things you should entice the eco-system to update and move with you rather than allow it to function with older assumptions. |
The only way I see then is that stdlib be released as separate packages (with a version number in the name since there will be a need to install several of them concurrently). One just increases the version number if there is backward compatibility and release a new package if not? ocaml packages could just be meta-packages depending on ocaml-compiler and stdlib (in order to keep the fact that they are blessed because they come with the compiler). |
I think the single remaining objection to this PR has been solved by 6a94394 and this can be merged. |
That being the only point of disagreement, I went ahead and merged. Thanks for your efforts and perseverance! |
Thanks @nojb ! |
@dbuenzli Despite my oppositions, I appreciate you volunteered to do those PRs. Thanks! |
Thanks @Drup and sorry again to have lost my temper, especially to @alainfrisch. |
Sure, no problem @dbuenzli. |
This PR improves stdlib support for
int
values. It adds anInt
module to the standard library and deprecates theint_of_string_opt
function.Deprecating
int_of_string
andstring_of_int
is a bit more involved on the code base and will be done in separate PRs.A few comments:
Bool
module proposal this PR includes only the non-raisingInt.of_string
function which corresponds toint_of_string_opt
. Here again I have nothing against renaming this function toof_string_opt
if this is desired.Nativeint
,Int32
andInt64
modules. In particular it does not define any operators.int
s of theStdlib
module could/should be deprecated aswell. This is not done by this PR but can be added. These functions aresucc
,pred
andabs
.exn
andunit
I think this is the last builtin datatype that was missing its own module. I'm sure you'll be glad to eventually be able to write{Set,Map}.Make (Int)
yourstdlib
-based programs !