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 mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id BE0797F780 for ; Fri, 13 May 2016 11:06:10 +0200 (CEST) IronPort-PHdr: 9a23:Tmu1jhAgMzVi2dse3J56UyQJP3N1i/DPJgcQr6AfoPdwSP/4osbcNUDSrc9gkEXOFd2CrakU2qyM6uu4AyQp2tWojjMrSNR0TRgLiMEbzUQLIfWuLgnFFsPsdDEwB89YVVVorDmROElRH9viNRWJ+iXhpQAbFhi3DwdpPOO9QteU1JTmkbrrsMWJKyxzxxODIppKZC2sqgvQssREyaBDEY0WjiXzn31TZu5NznlpL1/A1zz158O34YIxu38I46Fp34d6XK77Z6U1S6BDRHRjajhtpZ6jiR6WBzCI63QASGIO1lJtAgPF5Rz+FN+ltyrxtuNw3G+BOsD5UaozQRyj6btmTFnjjyJRc3Zz+2jSjol0jblHiBOnvR12hYDOKsnBP/N7eubZfMgGbWtHRMdYESJbVNCSdYwKWsMFNOde56fnpkAFrVPqDA2lBeWpxCVJnXT29ak3w+UvEEfN2wl2TIFGi2jdsNigbPRaauuy1qSdiGybN/4= Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=alain.frisch@lexifi.com; spf=None smtp.mailfrom=alain.frisch@lexifi.com; spf=None smtp.helo=postmaster@mx20.yaziba.net Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of alain.frisch@lexifi.com) identity=pra; client-ip=85.233.204.164; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain.frisch@lexifi.com"; x-sender="alain.frisch@lexifi.com"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of alain.frisch@lexifi.com) identity=mailfrom; client-ip=85.233.204.164; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain.frisch@lexifi.com"; x-sender="alain.frisch@lexifi.com"; x-conformance=sidf_compatible Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mx20.yaziba.net) identity=helo; client-ip=85.233.204.164; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="alain.frisch@lexifi.com"; x-sender="postmaster@mx20.yaziba.net"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0D3AADelzVXkKTM6VVehA0rU7lmgXYahXoCgTA6EgEBAQEBAQEBEQEBAQEJCwkJIS+CLYIWAQEEOBFACxguVwYBDAgBAReIGL8CDAEkhiWBdgiCT4QLNIVZBZgngVaGXIVsiT+FWo8/AicEgjsSCoFNbIhaAQEB X-IPAS-Result: A0D3AADelzVXkKTM6VVehA0rU7lmgXYahXoCgTA6EgEBAQEBAQEBEQEBAQEJCwkJIS+CLYIWAQEEOBFACxguVwYBDAgBAReIGL8CDAEkhiWBdgiCT4QLNIVZBZgngVaGXIVsiT+FWo8/AicEgjsSCoFNbIhaAQEB X-IronPort-AV: E=Sophos;i="5.24,613,1454972400"; d="scan'208";a="177693352" Received: from mx20.yaziba.net ([85.233.204.164]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/ADH-AES256-SHA; 13 May 2016 11:06:10 +0200 Received: from mta10.int.yaziba.net (mta10.int.yaziba.net [10.4.20.30]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx20.yaziba.net (mx10.yaziba.net) with ESMTPS id 1B4F51A77CE; Fri, 13 May 2016 11:06:09 +0200 (CEST) Received: from mta10.int.yaziba.net (localhost [127.0.0.1]) by mta10.int.yaziba.net (Postfix) with ESMTPS id 50FAECA656; Fri, 13 May 2016 11:06:09 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mta10.int.yaziba.net (Postfix) with ESMTP id 4050FCA753; Fri, 13 May 2016 11:06:09 +0200 (CEST) X-Virus-Scanned: amavisd-new at mta10.int.yaziba.net Received: from mta10.int.yaziba.net ([127.0.0.1]) by localhost (mta10.int.yaziba.net [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id RjZrEJuIL-6E; Fri, 13 May 2016 11:06:09 +0200 (CEST) Received: from [10.0.210.66] (unknown [185.23.92.144]) by mta10.int.yaziba.net (Postfix) with ESMTPSA id 1A88DCA656; Fri, 13 May 2016 11:06:09 +0200 (CEST) To: "Soegtrop, Michael" , "caml-list@inria.fr" References: <0F7D3B1B3C4B894D824F5B822E3E5A172CEF1630@IRSMSX102.ger.corp.intel.com> From: Alain Frisch Message-ID: <850765ff-25f1-ecb9-9707-74d3dc47675c@lexifi.com> Date: Fri, 13 May 2016 11:06:07 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.0 MIME-Version: 1.0 In-Reply-To: <0F7D3B1B3C4B894D824F5B822E3E5A172CEF1630@IRSMSX102.ger.corp.intel.com> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: quoted-printable X-DRWEB-SCAN: ok X-VRSPAM-SCORE: -100 X-VRSPAM-STATE: legit X-VRSPAM-CAUSE: gggruggvucftvghtrhhoucdtuddrfeekledrvddugddtlecutefuodetggdotefrucfrrhhofhhilhgvmecuggftfghnshhusghstghrihgsvgdpjgetkgfkueetnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefuvfhfhffkffgfgggjtgfgsehtqhertddtfeehnecuhfhrohhmpeetlhgrihhnucfhrhhishgthhcuoegrlhgrihhnrdhfrhhishgthheslhgvgihifhhirdgtohhmqeenucffohhmrghinhepihhnthgvlhdruggvnecukfhppedukeehrddvfedrledvrddugeegnecurfgrrhgrmhepmhhouggvpehsmhhtphhouhht X-VRSPAM-EXTCAUSE: mhhouggvpehsmhhtphhouhht Subject: Re: [Caml-list] Specify the default hash function for a type Dear Michael, Don't tell anybody (ahem), but the following might work depending on=20 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)= =20 with Obj.set_tag, then polymorphic hash *and* comparison functions will=20 use the "id" field and ignore the "foo" field (and any other extra=20 fields). It is important to keep "id" as the second field to mimic the=20 layout of real object values (and exception slots). In particular, this lets you easily "forget" sub-parts of a value (by=20 setting "id" to a fixed constant), or implement "references compared=20 with physical equality" (use a counter to assign unique "id" to each=20 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 record. > > > > 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 >