Skip to content
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

Closed
vicuna opened this issue Mar 18, 2009 · 8 comments
Closed

caml_hash_variant not available in standard library #4751

vicuna opened this issue Mar 18, 2009 · 8 comments

Comments

@vicuna
Copy link

vicuna commented Mar 18, 2009

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")?

@vicuna
Copy link
Author

vicuna commented Jun 1, 2012

Comment author: @garrigue

What would you need hash_variant for?
I see no legal use from inside ocaml.
You can already do it for fixed strings by (Obj.magic `Variant : int).
You can also copy the corresponding function from ocaml sources
(it is supposed to be fixed forever).

@vicuna
Copy link
Author

vicuna commented Jun 1, 2012

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.

@vicuna
Copy link
Author

vicuna commented Jul 10, 2012

Comment author: gares

+1 for this function in the Obj module.

I have a use case.
Coq marshals to disk its data structures (creating .vo files).
The coqchk tool verifies that .vo files have the right format (and also that
their content is sound). It is written in OCaml and uses Obj.* introspection facilities to verify the format (the type) of the marshaled data.

Without Obj.hash_variant polymorphic variants cannot be used in the data
structures Coq marshals to disk.

@vicuna
Copy link
Author

vicuna commented Mar 15, 2013

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.

You can also copy the corresponding function from ocaml sources
(it is supposed to be fixed forever).

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.

@vicuna
Copy link
Author

vicuna commented Oct 23, 2013

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.

@vicuna
Copy link
Author

vicuna commented Jul 22, 2016

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.

let hash_variant s =

@vicuna
Copy link
Author

vicuna commented Dec 7, 2016

Comment author: @mshinwell

FWIW, I don't think we should ever be recommending that functions are copied from the compiler distribution like this.

@vicuna
Copy link
Author

vicuna commented Dec 7, 2016

Comment author: @alainfrisch

If anyone is still interested in that, please submit a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants