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 Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by yquem.inria.fr (Postfix) with ESMTP id A6FF8BBAF for ; Wed, 8 Jul 2009 21:33:57 +0200 (CEST) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AlYCAIeRVErVpUAUi2dsb2JhbACOWIo4AQEBCgsKBxEFuA6ECAWBOg X-IronPort-AV: E=Sophos;i="4.42,370,1243807200"; d="scan'208";a="29495983" Received: from mail.gmx.net ([213.165.64.20]) by mail2-smtp-roc.national.inria.fr with SMTP; 08 Jul 2009 21:33:57 +0200 Received: (qmail invoked by alias); 08 Jul 2009 19:33:56 -0000 Received: from HSI-KBW-078-042-026-145.hsi3.kabel-badenwuerttemberg.de (EHLO colinux) [78.42.26.145] by mail.gmx.net (mp012) with SMTP; 08 Jul 2009 21:33:56 +0200 X-Authenticated: #33466693 X-Provags-ID: V01U2FsdGVkX1/RnO4404/RDDCCKk6tz86XXHs2Z7P6rNCR7kbEPx I5DAfeN6cxgKM8 Date: Wed, 8 Jul 2009 21:32:13 +0200 From: Bruno Daniel To: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Representation of different polymorphic variants guaranteed to be different? Message-ID: <20090708193213.GD3432@colinux> References: <20090708183527.GC3432@colinux> <20090708185415.GB11681@localhost> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20090708185415.GB11681@localhost> X-Y-GMX-Trusted: 0 X-FuHaFi: 0.54 X-Spam: no; 0.00; variants:01 variants:01 hashtbl:01 hashtbl:01 hash:01 0200,:01 translated:01 beginner's:01 ocaml:01 bug:01 2009:98 870:98 polymorphic:01 polymorphic:01 beginners:01 Dear Eric Cooper, thank you very much for your answer. I tried it out and I found that it really works, even with the variants defined in different ml-files linked together: --- module1.ml --- let a1 = if !Sys.interactive then `a else `zyctRecABC;; --- module2.ml --- let a2 = `ABC;; let _ = a2 = Module1.a1;; ------------------ or --- module2.ml --- let a2 = `ABC;; let h1 = Hashtb.create 100;; let _ = Hashtbl.replace h1 a2 0; Hashtbl.replace h1 Module1.a1 1;; ------------------ In both cases I get the following error message when compiling the second module: "Error: Variant tags `ABC and `zyctRecABC have the same hash value. Change one of them." But it's clear from this discussion that I'll never be allowed to use Obj.magic on variant types. The following goes through unchecked: --- module2.ml --- let a2 = `ABC;; let h1 : (int, int) Hashtbl.t = Hashtbl.create 100;; let _ = Hashtbl.replace h1 (Obj.magic a2) 0; Hashtbl.replace h1 (Obj.magic Module1.a1) 1;; ------------------ Best regards Bruno Daniel Eric Cooper wrote: > On Wed, Jul 08, 2009 at 08:35:27PM +0200, Bruno Daniel wrote: >> 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? > > See this thread: > http://caml.inria.fr/pub/ml-archives/caml-list/2005/03/544288096a47d82ec870d01c8396f5fe.fr.html > > Short answer: collisions could theoretically occur, but are detected > at link time. > > -- > Eric Cooper e c c @ c m u . e d u > > _______________________________________________ > Caml-list mailing list. Subscription management: > http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list > Archives: http://caml.inria.fr > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs