From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 4943B7FA66 for ; Fri, 13 May 2016 15:50:52 +0200 (CEST) IronPort-PHdr: 9a23:/ibX9Bc2/hYCfqijbarO4fwilGMj4u6mDksu8pMizoh2WeGdxc+yZx7h7PlgxGXEQZ/co6odzbGG4ua6ACdeu96oizMrTt9lb1c9k8IYnggtUoauKHbQC7rUVRE8B9lIT1R//nu2YgB/Ecf6YEDO8DXptWZBUiv2OQc9HOnpAIma153xjLDjvceKKFsSzBOGIppMbzyO5T3LsccXhYYwYo0Q8TDu5kVyRuJN2GlzLkiSlRuvru25/Zpk7jgC86l5r50IeezAcq85Vb1VCig9eyBwvZWz9EqLcQzaz38VU2NevABJGAPFpEXzWp7wtG30rOtm0ymyOcDmTL41Hz+l6vEvAFXTjyoIKyQ+6CWfr817jKtWpFjp8xl+yI7dbYXTL/1zcb/HessyRGxdU8IXXCtEVMf0JYAGCu5EOedDs6H8oUEPpF2wH0PkUOjmzzsNgn7twYU71f4gGEfIxlpzMcgJtSHsrdjvLqpaeuC8yaPB1ymLO+tX1C3n5c7Dchkkq/iWQZp3esPUzVE1EEXOiVDG+t+tBC+cyulY6zvT1OFnT+/6zjd/8ww= Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=pierre.chambart@ocamlpro.com; spf=None smtp.mailfrom=pierre.chambart@ocamlpro.com; spf=Pass smtp.helo=postmaster@redisdead.crans.org Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of pierre.chambart@ocamlpro.com) identity=pra; client-ip=138.231.136.39; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="pierre.chambart@ocamlpro.com"; x-sender="pierre.chambart@ocamlpro.com"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of pierre.chambart@ocamlpro.com) identity=mailfrom; client-ip=138.231.136.39; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="pierre.chambart@ocamlpro.com"; x-sender="pierre.chambart@ocamlpro.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of postmaster@redisdead.crans.org designates 138.231.136.39 as permitted sender) identity=helo; client-ip=138.231.136.39; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="pierre.chambart@ocamlpro.com"; x-sender="postmaster@redisdead.crans.org"; x-conformance=sidf_compatible; x-record-type="v=spf1" X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CMAADn2jVXhieI54pehAx+uWWBdhqFegKBMDkTAQEBAQEBAQERAQEBChYHUIItghYBAQRJLxELGAkWDwkDAgECAUUGAQwIAheIFAXATAwBJIYlhE2ECzSFWQEEmCeBVoZch1WET4MHhVqPQSIBgkQSCoFNbIhaAQEB X-IPAS-Result: A0CMAADn2jVXhieI54pehAx+uWWBdhqFegKBMDkTAQEBAQEBAQERAQEBChYHUIItghYBAQRJLxELGAkWDwkDAgECAUUGAQwIAheIFAXATAwBJIYlhE2ECzSFWQEEmCeBVoZch1WET4MHhVqPQSIBgkQSCoFNbIhaAQEB X-IronPort-AV: E=Sophos;i="5.24,614,1454972400"; d="scan'208";a="218188768" Received: from redisdead.crans.org ([138.231.136.39]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/ADH-AES256-GCM-SHA384; 13 May 2016 15:50:51 +0200 Received: from [134.157.22.158] (unknown [134.157.22.158]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by redisdead.crans.org (Postfix) with ESMTPSA id 60F13161A; Fri, 13 May 2016 15:50:51 +0200 (CEST) To: Alain Frisch , "Soegtrop, Michael" , "caml-list@inria.fr" References: <0F7D3B1B3C4B894D824F5B822E3E5A172CEF1630@IRSMSX102.ger.corp.intel.com> <850765ff-25f1-ecb9-9707-74d3dc47675c@lexifi.com> From: Pierre Chambart Organization: OcamlPro Message-ID: <5735DBB9.5050101@ocamlpro.com> Date: Fri, 13 May 2016 15:50:49 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Icedove/38.6.0 MIME-Version: 1.0 In-Reply-To: <850765ff-25f1-ecb9-9707-74d3dc47675c@lexifi.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Validation-by: pierre.chambart@ocamlpro.com Subject: Re: [Caml-list] Specify the default hash function for a type For those who don't see that as a joke, please forget everything about that. Obj.set_tag is an extremely dangerous function as the compiler assumes that value's tag never change, even for completely unknown values. Hence, it might be legal for the compiler to do something that you might not expect on: let f x =3D let x' =3D Obj.repr x in let tag =3D Obj.tag x' in Obj.set_tag x' 0 let ... =3D match x with ... in Obj.set_tag x' tag; match x with ... The access to the tag can be shared for instance. And lots of 'surprising' stuff might happen. This is of course a quite brutal example but this could apply to a lot of less obvious situation ! So Obj.magic and Obj.set_field : bad Obj.set_tag: really really bad ! --=20 Pierre On 13/05/2016 11:06, Alain Frisch wrote: > Dear Michael, > > Don't tell anybody (ahem), but the following might work depending on > your exact use case... > > If you define a type such as: > > type t =3D { > foo: ....; > id: int; > } > > and if you set the tag of values for this type to Obj.record_tag (=3D > 248) with Obj.set_tag, then polymorphic hash *and* comparison > functions will use the "id" field and ignore the "foo" field (and any > other extra fields). It is important to keep "id" as the second field > to mimic the layout of real object values (and exception slots). > > In particular, this lets you easily "forget" sub-parts of a value (by > setting "id" to a fixed constant), or implement "references compared > with physical equality" (use a counter to assign unique "id" to each > such reference). > > > Best regards, > > Alain > > > > On 13/05/2016 09:52, Soegtrop, Michael wrote: >> Dear Ocaml Users, >> >> >> >> I wonder if there is a way to specify a default hash function for a >> type, which is then used by the automated hash functions e.g. created >> for records containing this type. I have e.g. a record with about 10 >> fields and I am happy with the default hash functions for most fields >> and for the record, but for just one field I would like to use a custom >> hash function, but I don=92t want to write a hash function for the recor= d. >> >> >> >> I am currently using the standard library, but if there is a solution >> with Batteries or Core, I would also be interested. >> >> >> >> Best regards, >> >> >> >> Michael >> >> Intel Deutschland GmbH >> Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany >> Tel: +49 89 99 8853-0, www.intel.de >> Managing Directors: Christin Eisenschmid, Christian Lamprechter >> Chairperson of the Supervisory Board: Nicole Lau >> Registered Office: Munich >> Commercial Register: Amtsgericht Muenchen HRB 186928 >> >