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
caml_hash_variant not available in standard library #4751
Comments
Comment author: @garrigue What would you need hash_variant for? |
Comment author: @mmottl If I remember correctly, this function was needed back then for some code generation or preprocessing stuff. I implemented it in OCaml for the type_conv library, but it's actually not used by any public library anymore. It's presumably not super-important. |
Comment author: gares +1 for this function in the Obj module. I have a use case. Without Obj.hash_variant polymorphic variants cannot be used in the data |
Comment author: mbarbin +1 for this function in the Obj module. If you do some type related preprocessing it is likely that you'll end up needing it. I also have a use case for it in a piece of code that deals with runtime types.
this is indeed in practice what we do for now at janestreet, paired with a few unit tests to make sure this matches what the compiler does, but it seems like a binding would be better. the stability of the computation can be discussed separately I guess. |
Comment author: @bobzhang I have another use case for partial evaluation, if the user knows the literal string at the compile time, we can pre-hash the string and then compare the integer instead of string, which is much faster. |
Comment author: qrntz Just in case anyone still needs hash_variant and would rather avoid C stubs, there's an analogous implementation in btype.ml. Line 184 in 502e4f9
|
Comment author: @mshinwell FWIW, I don't think we should ever be recommending that functions are copied from the compiler distribution like this. |
Comment author: @alainfrisch If anyone is still interested in that, please submit a pull request. |
Original bug ID: 4751
Reporter: @mmottl
Assigned to: @garrigue
Status: resolved (set by @alainfrisch on 2016-12-07T17:22:22Z)
Resolution: suspended
Priority: normal
Severity: feature
Version: 3.11.0
Category: standard library
Monitored by: @bobzhang @glondu @Chris00 @mmottl
Bug description
The runtime C-function "caml_hash_variant", which takes a string and calculates the hash value associated with e.g. a polymorphic variant of that name, is currently not callable from within OCaml. Could you please add a binding for it to some module in the standard library (maybe Hashtbl, next to "hash")?
The text was updated successfully, but these errors were encountered: