From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: ** X-Spam-Status: No, score=2.6 required=5.0 tests=RCVD_IN_SORBS_WEB,SPF_FAIL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by yquem.inria.fr (Postfix) with ESMTP id 838DDBBAF for ; Wed, 8 Jul 2009 20:37:13 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhMDAPCDVErVpUAUi2dsb2JhbACOfAGKEwEBAQoLCgcRBbgzhAgF X-IronPort-AV: E=Sophos;i="4.42,369,1243807200"; d="scan'208";a="43132133" Received: from mail.gmx.net ([213.165.64.20]) by mail4-smtp-sop.national.inria.fr with SMTP; 08 Jul 2009 20:37:12 +0200 Received: (qmail invoked by alias); 08 Jul 2009 18:37:12 -0000 Received: from HSI-KBW-078-042-026-145.hsi3.kabel-badenwuerttemberg.de (EHLO colinux) [78.42.26.145] by mail.gmx.net (mp032) with SMTP; 08 Jul 2009 20:37:12 +0200 X-Authenticated: #33466693 X-Provags-ID: V01U2FsdGVkX1/oJDYrF1nohBJuLQSUPQW3JecTfndq9eK14ohVoJ NJwdx60qtNzNBa Date: Wed, 8 Jul 2009 20:35:27 +0200 From: Bruno Daniel To: caml-list@yquem.inria.fr Subject: Representation of different polymorphic variants guaranteed to be different? Message-ID: <20090708183527.GC3432@colinux> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Y-GMX-Trusted: 0 X-FuHaFi: 0.6 X-Spam: no; 0.00; variants:01 ocaml:01 variants:01 ocaml:01 hash:01 hash:01 ocaml-:01 asmrun:01 ocaml-:01 btype:01 constructors:01 translated:01 foo:01 foo:01 polymorphic:01 Dear OCaml developers, I'm trying to understand the representation of polymorphic variants in OCaml and I'm a bit worried about possible problems. Section 18.3.6 of the OCaml 3.11 reference manual reads: "[...] The variant value `VConstr is represented by hash_variant("VConstr"). The variant value `VConstr(v) is represented by a block of size 2 and tag 0, with field number 0 containing hash_variant("VConstr") and field number 1 containing v." I take it from the source code of caml_hash_variant in ocaml-3.11.1_src/asmrun/hash.c and hash_variant in ocaml-3.11.1_src/typing/btype.ml that hash_variant returns an OCaml 31-bit integer value, i.e. there is only room for at most 2147483648 different polymorphic variants, but even with identifiers composed of only 7 characters chosen from 26 letters one could easily construct 8031810176 different polymorphic variant constructors. How is it ensured that I get a <> b for a and b created as polymorphic variants from two different identifiers? Will pattern matching give wrong results if I accidentally choose two different identifiers translated to the same internal representation? The same applies to method names according to section 18.3.5: "Since public method tags are hashed in the same way as variant tags, and methods are functions taking self as first argument, if you want to do the method call foo#bar from the C side, you should call: callback(caml_get_public_method(foo, hash_variant("bar")), foo);". I apologize if these questions have been answered before. I couldn't find any discussion about them in the archives. Thank you very much for your help. Best regards Bruno Daniel