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 mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id 3D1447EEDB for ; Sun, 28 Oct 2012 14:50:12 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of yminsky@janestreet.com) identity=pra; client-ip=38.105.200.112; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="yminsky@janestreet.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of yminsky@janestreet.com designates 38.105.200.112 as permitted sender) identity=mailfrom; client-ip=38.105.200.112; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="yminsky@janestreet.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@nyc-dmz-mxout1.janestreet.com) identity=helo; client-ip=38.105.200.112; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="yminsky@janestreet.com"; x-sender="postmaster@nyc-dmz-mxout1.janestreet.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhICAL83jVAmachwnGdsb2JhbABEwlcrAQEBAQEIHTuCNwITGQEBOCVdEgEFARZBh2QDnFJiCQOKc4QzAQWOLQaPLoMklXeOYRYphC2BfQ X-IronPort-AV: E=Sophos;i="4.80,665,1344204000"; d="scan'208";a="160673001" Received: from mx1.janestreet.com (HELO nyc-dmz-mxout1.janestreet.com) ([38.105.200.112]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-SHA; 28 Oct 2012 14:49:49 +0100 Received: from nyc-qsv-mail1.delacy.com ([172.25.22.57]) by nyc-dmz-mxout1.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1TSTFK-00034Y-QK for caml-list@inria.fr; Sun, 28 Oct 2012 09:49:46 -0400 Received: from nyc-dmz-mxgoog1.delacy.com ([172.25.224.109] helo=mxgoog1.janestreet.com) by nyc-qsv-mail1.delacy.com with esmtps (TLSv1:AES256-SHA:256) (Exim 4.76) (envelope-from ) id 1TSTFK-0002fG-Oy for caml-list@inria.fr; Sun, 28 Oct 2012 09:49:46 -0400 Received: from mail-gg0-f198.google.com ([209.85.161.198]) by mxgoog1.janestreet.com with esmtp (Exim 4.76) (envelope-from ) id 1TSTFK-0008I1-My for caml-list@inria.fr; Sun, 28 Oct 2012 09:49:46 -0400 Received: by mail-gg0-f198.google.com with SMTP id o1so10932434ggn.9 for ; Sun, 28 Oct 2012 06:49:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=janestreet.com; s=google; h=mime-version:x-originating-ip:date:message-id:subject:from:to :content-type; bh=2UAamcr1YhRCF4MSBZ+pM76RgXWro3RCkUZvW4SV4kc=; b=rDPeVjM+TcyOPEpknpaM1ZHUDhBbzCpnyOl9CsxXujrWz9GSWk80F5vMnSnySJKAV2 VFl26r7N0aGCuzzOeORZaAqto/ocaub6QFyZI+I78UWmlYcrtL5LpccwTDVL0opIlUQ5 pDbJzi+sl4g77KV4Os97Zshrll0d95mnwLiwg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-originating-ip:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=2UAamcr1YhRCF4MSBZ+pM76RgXWro3RCkUZvW4SV4kc=; b=aASvBayxwrSSENuy+bFC/sjiLz8GUg74dEkL7jQNvL2WwTYbPPKNxb+hDvbwhfCSdO Nhjwt1tZ6o1hAgJxkSB5aTwb0wi6/gF7YnFDFPOszfUeNmiIdt/TWR0g/hoTnsyW33ls K40kwa/gWxYChIbOcjP76+aqieVTVZTUI1j3mBDE53UqEHzObijZFzmnOMQm8Ox8hPvC v3taOMqJgU+h7owG8zGIvqXjHxOmAlkU8dHhtlKhCY4jyGPCM0QoG/Dn7yvIApaDFivT XKZal9XbjKmMjJ9zttjfScQqGVyhsDXCZrN617WTZ5W/4Al3exsgOB36bPYw/g0onwRU WIPw== Received: by 10.52.28.130 with SMTP id b2mr35588060vdh.117.1351432186427; Sun, 28 Oct 2012 06:49:46 -0700 (PDT) MIME-Version: 1.0 Received: by 10.52.28.130 with SMTP id b2mr35588053vdh.117.1351432186355; Sun, 28 Oct 2012 06:49:46 -0700 (PDT) Received: by 10.58.228.231 with HTTP; Sun, 28 Oct 2012 06:49:46 -0700 (PDT) X-Originating-IP: [72.225.238.212] Date: Sun, 28 Oct 2012 09:49:46 -0400 Message-ID: From: Yaron Minsky To: caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 X-Gm-Message-State: ALoCoQlkZhx0sM8h+PQi0CulezmUtOJEnRSk2tESmwqXplh7JgVFECkjFtvO30Y59pJr3/alr6GjCi9ey8igseuB4uPdoKFOFKIW4oX9cfS+QPQzKcXkT06k0jP99+xx13ThsiB4ElXn9U5BheFWVSulFR2kAz3K3A== Subject: [Caml-list] explaining polymorphic variants A question that came up in the section of Real World OCaml on polymorphic variants. I'm wondering if someone can explain the error in the third definition below. # let handle_a `A = "a";; val handle_a : [< `A ] -> string = # let handle_ab (x: [`A | `B ]) = match x with |`B -> "b" | `A as a -> handle_a a ;; val handle_ab : [ `A | `B ] -> string = # let handle_ab' (x: [`A | `B ]) = match x with | `B -> "b" | a -> handle_a a ;; Characters 86-87: | a -> handle_a a ^ Error: This expression has type [ `A | `B ] but an expression was expected of type [< `A ] The second variant type does not allow tag(s) `B I understand roughly what's going on here. In the definition of handle_ab, there is a straightforward syntactic basis for narrowing the type of the variable a. In the case of handle_ab', that syntactic basis is no longer available, and so the type of a is not narrowed. But the question is: why isn't it narrowed based on the other information available? It seems in theory possible to infer the narrower type in this case. Does anyone have a satisfying explanation as to why? y