From mboxrd@z Thu Jan 1 00:00:00 1970 X-Sympa-To: caml-list@inria.fr Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id p3SJGMW8019960 for ; Thu, 28 Apr 2011 21:16:22 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AnACABS8uU3RVaE2kGdsb2JhbACYUo0rCBQBAQEBCQkNBxQEIadagkKKfIInhSw0iF4BAQMGhXAEjlyKKDuDQg X-IronPort-AV: E=Sophos;i="4.64,282,1301868000"; d="scan'208";a="107016365" Received: from mail-fx0-f54.google.com ([209.85.161.54]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 28 Apr 2011 21:16:16 +0200 Received: by fxm11 with SMTP id 11so4255229fxm.27 for ; Thu, 28 Apr 2011 12:16:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:date:message-id:subject:from:to :content-type; bh=7OGSVhSN8JEeWam52xiOa3fLD1ke30R/9ocFBGnTeFc=; b=Jo8x8oOd2MrHaYrRmKz+VPhaulEwxOZQmuJCeNHszItd2lhUNFhlTUeCnuecaYVdKY rPNcp4ECYT7XOxY+A/G5qP/szh8pasBLtbeLP07Isw2A29GHZ9kI9PfBV1nwYFZ0eRqS ga5ML+7DWlvJfR2K4jQxuGhfNVvP2/2JmmP1k= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=WMA9vwGYCLSeIkNQ9onh7dKTTL0FbDUSjcTUcmPG180qk67+Ard0ebiEgi9qkuAh6w jIowm8gjyplFZeH2teg4KkGkdLcuHjR4jBNeKSPhSZ5YaiYH+0O9uzEIrjQMHcu6t5t3 Am7zEUpleXcPJhRpYJLlzSmvVQbR7dtXpQTMU= MIME-Version: 1.0 Received: by 10.223.31.133 with SMTP id y5mr1713758fac.7.1304018176417; Thu, 28 Apr 2011 12:16:16 -0700 (PDT) Received: by 10.223.96.197 with HTTP; Thu, 28 Apr 2011 12:16:16 -0700 (PDT) Date: Thu, 28 Apr 2011 15:16:16 -0400 Message-ID: From: Ethan Burns To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 X-Validation-by: burns.ethan@gmail.com Subject: [Caml-list] Comparing variant types Hi, I have a program that uses variant types as an enumeration. While profiling, I noticed that compare_val was being called a bunch. When I went to inspect why this was the case, it turns out that it was being called to compare equality of my variants. I am a bit confused, however, because my understanding was that variants that are declared without an 'of' clause were just represented as integers and therefore a type containing only these simple elements should be directly comparable (no compare_val). While looking further into this, I found a little example where the compiler seems to produce a simple comparison in one case and not in another: type dir = Left | Right | Up | Down | No_op (* performs a simple comparison *) let f a = a <> Right (* calls out to C to do compare_val *) let g (a:dir) b = a <> b There is the -dlambda output: (seq (let (f/69 (function a/70 (!= a/70 1a))) (setfield_imm 0 (global Test!) f/69)) (let (g/71 (function a/72 b/73 (caml_notequal a/72 b/73))) (setfield_imm 1 (global Test!) g/71)) 0a) Since both functions know that the types of the elements being compare is 'dir', which contains only simple elements, why does the g function still use compare_val? Does the compiler not perform this particular optimization? Best, Ethan