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 291147FA5C for ; Fri, 13 May 2016 14:01:56 +0200 (CEST) IronPort-PHdr: 9a23:bMumahFReDvZIDunX6DxcZ1GYnF86YWxBRYc798ds5kLTJ74psqwAkXT6L1XgUPTWs2DsrQf27uQ6fmrBTVIyK3CmU5BWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYsExnyfTB4Ov7yUtaLyZ/nhqbootaPOk1hv3mUX/BbFF2OtwLft80b08NJC50a7V/3mEZOYPlc3mhyJFiezF7W78a0+4N/oWwL46pyv+YJa6jxfrw5QLpEF3xmdjltvIy4gyLeVhOC7WcwVWAfkxwAQ1SUrUKyYpCk+BD9u+Vhwi6CeYXTTLs0UDmmpe8/TR7jiC4KM3gi92zYltZ3lIpapg6so1p0xIuCM6+PM/8rUarXZ9IXQSJ6VcZcTSFbStezZoEVDucFe/1Tr4TnqkEmoh63BA3qD+TqnGwbzkTq1LE3hrxyWTrN2xYtSpdT6Xk= Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-io0-f175.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.223.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.223.175 as permitted sender) identity=mailfrom; client-ip=209.85.223.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-io0-f175.google.com) identity=helo; client-ip=209.85.223.175; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-io0-f175.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0CuAAAZwTVXiK/fVdFehAx+BqcQgVOFY40PIoVyAoEoBzsRAQEBAQEBAQERAQEBCAsLCR8xgi2CFQEBAQQSER0BCBMSCwEDCAQGBQsGBAEBAQICCRoDAgIiAREBBQEKAQkIBhMSEIdyAQMXDqEHgTE+MYs7gWqCWAWHOwoZJwMKUoNbAQEBAQEBAQEBAQEBAQEBAQEBARYCBhBxhSSETYc/glkFhjsMhxeKSYFWhCiIIII3jGKOAxIegQ42giUMEgqBZyAyAQGIWAEBAQ X-IPAS-Result: A0CuAAAZwTVXiK/fVdFehAx+BqcQgVOFY40PIoVyAoEoBzsRAQEBAQEBAQERAQEBCAsLCR8xgi2CFQEBAQQSER0BCBMSCwEDCAQGBQsGBAEBAQICCRoDAgIiAREBBQEKAQkIBhMSEIdyAQMXDqEHgTE+MYs7gWqCWAWHOwoZJwMKUoNbAQEBAQEBAQEBAQEBAQEBAQEBARYCBhBxhSSETYc/glkFhjsMhxeKSYFWhCiIIII3jGKOAxIegQ42giUMEgqBZyAyAQGIWAEBAQ X-IronPort-AV: E=Sophos;i="5.24,614,1454972400"; d="scan'208,223";a="177715879" Received: from mail-io0-f175.google.com ([209.85.223.175]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 13 May 2016 14:01:55 +0200 Received: by mail-io0-f175.google.com with SMTP id d62so129619036iof.2 for ; Fri, 13 May 2016 05:01:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=NHKYOXIVAMdv8kHH/RGjMa8K7WkXW78akixBOZaUEHI=; b=JltU6f5U49AdSjzp81CYq96AaeYYopUuQpA0Iw/kwNHAUjiomciJtf2XSNY7wYT9Eg zl48Kd9s12sHMqduBKy7gyYCF6d3420zXAdZOoENK/TjgaL3JIyXzuiS96UIUCeWIrT3 b3pN+6FiK5xNQo/7FsT6P2Rrky8UGK+NEeHWugDW4ejskqmKVsopU2F0jTLvZSYX3U70 CaSrTQI/9/+ID5IoeqC5l5b1p2rOgQnEd2Lda5NQycEA5FlOHVYnCEdRcPtbH16fz72M cJQPTC5gASeRzSoduVvc1VCkpJmF7l97sgbgsZaINcCZ+mhao4dVh+nlmJ2VmRafiUHw G/FA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=NHKYOXIVAMdv8kHH/RGjMa8K7WkXW78akixBOZaUEHI=; b=iTKsX1CpnbgZC7HEGzzJHF5JEN4BFG2XbZN7RTUaVmNuKe80peRdIQhjuY4u25aSsf mfbn5pjgZfmStELgVS9VSu9IZoNYhw8q3y+v9p29qCMNCmaidKhj7ribzrS25MVZa/1B aPeZ3lQw6EsZdfpRWsjaRKyke5A6YXh9hNLgF7k+vtKLdu9k8BKeqqI09EMLUOMBDAy/ 5IsiUTsYs6BuvjQreRD/WDmYaXEl6iGZKpjl45Tb5bhSCN+FK5Y7SWbn2jGCax1sN+IM VHRv4ZAHTRKFyaTvYnPRPH8jwHZ/HarRiVT1kEOXFW7OjR+V2Bjqnf4BTsIWY6r2fZor VPqg== X-Gm-Message-State: AOPr4FV4sb4FvkIXS9JnzhkQtIveq2UDxVwz3Fu4N+7/+/rKBukmQsGlXaQX0Yi1e1suQKwmIEyEhnDPzadTrQ== X-Received: by 10.36.124.138 with SMTP id a132mr357773itd.21.1463140913912; Fri, 13 May 2016 05:01:53 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.89.195 with HTTP; Fri, 13 May 2016 05:01:14 -0700 (PDT) In-Reply-To: <0F7D3B1B3C4B894D824F5B822E3E5A172CEF175C@IRSMSX102.ger.corp.intel.com> References: <0F7D3B1B3C4B894D824F5B822E3E5A172CEF1630@IRSMSX102.ger.corp.intel.com> <850765ff-25f1-ecb9-9707-74d3dc47675c@lexifi.com> <0F7D3B1B3C4B894D824F5B822E3E5A172CEF175C@IRSMSX102.ger.corp.intel.com> From: Gabriel Scherer Date: Fri, 13 May 2016 08:01:14 -0400 Message-ID: To: "Soegtrop, Michael" Cc: Alain Frisch , "caml-list@inria.fr" Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] Specify the default hash function for a type >From the C side it is possible to create "custom" values that come with user-specified comparison and hashing functions. However, for now the runtime does not allow creating them from OCaml -- this is indeed a desirable feature, but it's not trivial to implement. I don't really whether it's actually "really hard", or just that it requires some effort that nobody has invested yet -- the latter would be my guess. If you don't mind going through a C stubs to do this, you could thus create the custom value in C land, and export that in OCaml land. See the manual: Interfacing C with OCaml > custom blocks http://caml.inria.fr/pub/docs/manual-ocaml-4.03/intfc.html#sec442 On Fri, May 13, 2016 at 5:26 AM, Soegtrop, Michael wrote: > Dear Alain, > > this are temptations on Friday morning ... I guess as a beginner I should resist, not be lazy, and write the hash function by hand. But I put it into appendix D of my OCaml notes ;-) > > Best regards, > > Michael > >> -----Original Message----- >> From: Alain Frisch [mailto:alain.frisch@lexifi.com] >> Sent: Friday, May 13, 2016 11:06 AM >> To: Soegtrop, Michael; caml-list@inria.fr >> 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 your >> exact use case... >> >> If you define a type such as: >> >> type t = { >> foo: ....; >> id: int; >> } >> >> and if you set the tag of values for this type to Obj.record_tag (= 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 > 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 > > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs