Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0004751OCamlstandard librarypublic2009-03-18 20:102016-12-07 18:22
Assigned Togarrigue 
PlatformOSOS Version
Product Version3.11.0 
Target VersionFixed in Version 
Summary0004751: caml_hash_variant not available in standard library
DescriptionThe 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")?
TagsNo tags attached.
Attached Files

- Relationships

-  Notes
garrigue (manager)
2012-06-01 09:45

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).
mottl (reporter)
2012-06-01 15:04

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.
gares (reporter)
2012-07-10 18:52

+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.
mbarbin (reporter)
2013-03-15 15:02

+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.
hongboz (developer)
2013-10-23 17:14

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.
qrntz (reporter)
2016-07-22 19:19

Just in case anyone still needs hash_variant and would rather avoid C stubs, there's an analogous implementation in [^]
shinwell (developer)
2016-12-07 18:01

FWIW, I don't think we should ever be recommending that functions are copied from the compiler distribution like this.
frisch (developer)
2016-12-07 18:22

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

- Issue History
Date Modified Username Field Change
2009-03-18 20:10 mottl New Issue
2009-04-29 15:42 doligez Status new => acknowledged
2012-06-01 09:45 garrigue Note Added: 0007497
2012-06-01 09:45 garrigue Assigned To => garrigue
2012-06-01 09:45 garrigue Status acknowledged => feedback
2012-06-01 15:04 mottl Note Added: 0007502
2012-06-01 15:04 mottl Status feedback => assigned
2012-07-10 18:52 gares Note Added: 0007695
2013-03-15 15:02 mbarbin Note Added: 0008973
2013-10-23 17:14 hongboz Note Added: 0010524
2016-07-22 19:19 qrntz Note Added: 0016114
2016-12-07 18:01 shinwell Note Added: 0016752
2016-12-07 18:01 shinwell Category OCaml general => OCaml standard library
2016-12-07 18:22 frisch Note Added: 0016762
2016-12-07 18:22 frisch Status assigned => resolved
2016-12-07 18:22 frisch Resolution open => suspended
2017-02-23 16:43 doligez Category OCaml standard library => standard library

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker