-
Notifications
You must be signed in to change notification settings - Fork 9
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
Explicitly mark functions as unsafe and add safe versions #49
Comments
I'm sympathetic to this, but I'm also not sure about making such a change. This library is very similar in spirit to primitive, in the saying "users are expected to know what they're doing". At the same time, there's more toolbox safe/high-level functions here than in primitive. Another point against this change is that the safety of a function is supposed to be super obvious from its type here: If you have e.g. (making up code) I think at the very minimum this should be thoroughly documented. I'm mildly +1 on making some kind of change to improve the names of things to make their safety clearer, because names are still really helpful. |
It should definitely be documented which functions are safe and which aren't. Currently, the only indication of that is that it uses the |
I don't think it is reasonable at all to assume UB from a type signature. Well-typed programs should not go wrong, and should at least not cause UB. I also assume that I think we can make the api safe without breaking it. If we add bounds checking to all the currently unsafe functions, the api remains the same. Then, we can add |
Good point about UB vs Exceptions. Primitive itself doesn't work like this (just UB everywhere) but it definitely violates most Haskeller's understanding. If we want to make primitive operations more approachable (one of the very goals of this library as a unification of array APIs), then we should look at improving on this too. So, concretely, for every relevant function, having three versions:
along with good documentation for everything so users fully understand the breadth of consequences of their choice |
FWIW I've been attracted to exception types such as the two provided by the following library: https://github.com/riz0id/array-exceptions |
I'm sometimes against the name X being given to the one which throws the exception and not the "totally" safe version (which i referred to as tryX), such as when i use vector. But I'll need to think about that later. |
Some prior art:
|
This deserves mention, thanks. Although I'm not a fan, I don't know of better operator name alternatives. |
@andrewthad any thoughts on this? |
I much prefer having separate modules to prefixing the function names. I think the easiest backwards compatible way to do this would just be to introduce a safe module and an unsafe module and re-export appropriate functions from each. |
I really like this library, and would like to use it in projects. One thing that is stopping me is that safe and unsafe functions are mixed together. The juxtaposition of high level and low level unsafe functions confuses me. If this library wanted to include a typeclass around
primitive
, it would make sense. I think that it would be better to add anunsafe
prefix or put unsafe functions in a separate module, then add safe versions. What are your thoughts on this?The text was updated successfully, but these errors were encountered: