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 mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 9549D7F1AA for ; Thu, 10 Sep 2015 11:13:10 +0200 (CEST) IronPort-PHdr: 9a23:r0kZ/RMP/SmxauZlrI8l6mtUPXoX/o7sNwtQ0KIMzox0KPT4rarrMEGX3/hxlliBBdydsKIYzbOK+4nbGkU+or+5+EgYd5JNUxJXwe43pCcHRPC/NEvgMfTxZDY7FskRHHVs/nW8LFQHUJ2mPw6anHS+4HYoFwnlMkItf6KuStKU1pj//tvx0qOQSj0AvCC6b7J2IUf+hiTqne5Sv7FfLL0swADCuHpCdrce72ppIVWOg0S0vZ/or9ZLuh5dsPM59sNGTb6yP+FhFeQZX3waNDUQ7df3tB+LYQaq638YVS1ClxNSHwnD4Bz/U5P1tQP1s+N83G+ROsigHp4uXjH3wK5hUh7ljG88PD406mzNwph/hahBoR+l4Qd0w4PObZu9O/93f6ebdtQfEzkSFv1NXjBMV9vvJ7AECPAMaKMB99Hw Authentication-Results: mail2-smtp-roc.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-f174.google.com Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.223.174; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.223.174 as permitted sender) identity=mailfrom; client-ip=209.85.223.174; receiver=mail2-smtp-roc.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 (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-io0-f174.google.com) identity=helo; client-ip=209.85.223.174; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-io0-f174.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DAAQB+SPFVlK7fVdFdg0I1aQaDIKdVlCuFdwoCgTgHPBABAQEBAQEBARABAQEBBwsLCR8wgh2CBwEBBBIRBBkBGx0BAwwGBQsNAgImAgIhAQERAQUBHAYTIod2AQMSqSeBMD4xi0GBbIJ5iXMKGScNVoQWAQEBBwEBAQEYAQUOgRSFUYR7gk+CPQeCaYFDBZVWhQqGA4FtghKRKoVwEiOBFziCLoF/PDOISQEBAQ X-IPAS-Result: A0DAAQB+SPFVlK7fVdFdg0I1aQaDIKdVlCuFdwoCgTgHPBABAQEBAQEBARABAQEBBwsLCR8wgh2CBwEBBBIRBBkBGx0BAwwGBQsNAgImAgIhAQERAQUBHAYTIod2AQMSqSeBMD4xi0GBbIJ5iXMKGScNVoQWAQEBBwEBAQEYAQUOgRSFUYR7gk+CPQeCaYFDBZVWhQqGA4FtghKRKoVwEiOBFziCLoF/PDOISQEBAQ X-IronPort-AV: E=Sophos;i="5.17,503,1437429600"; d="scan'208";a="176812535" Received: from mail-io0-f174.google.com ([209.85.223.174]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 10 Sep 2015 11:13:09 +0200 Received: by ioiz6 with SMTP id z6so53095911ioi.2 for ; Thu, 10 Sep 2015 02:13:08 -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:content-type; bh=PmX+V6QvmN42BcCh31dkvN/2OGKpvKmaPl4IeClqq6I=; b=P/wHBJu1Ys8IAeOghcJ4QWuhzHtar5knDxeTo7mIA70DRsFVHJhq6J4pPulkGrhZby Y9XkXGk5Jl/ty+dNBeRRLu3PaqT4ej+iVAPehnnuaPddexKseqjKM/XVanXlJIpSesVb 8GZEVaPPqytRMoWpS+pL7YI8SeUmqWGHSMZegeIs2jnicTDxA/iNAkwsGv6SKwj58i55 q4rSyL7Q1GlVbt2GGR0J3MiuAPJiZzSrWnP+4AolLDvOmNbj81dwnPmSDwz9rPDzb9eA V4JWvyu+/VPQWPuYJHNI9YSBLA1ewrkClDf+8lsX2n51kXoEDkVYLUpqLVvlpei0apoF FtfA== X-Received: by 10.107.19.70 with SMTP id b67mr57277684ioj.144.1441876388692; Thu, 10 Sep 2015 02:13:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.79.19.68 with HTTP; Thu, 10 Sep 2015 02:12:29 -0700 (PDT) In-Reply-To: References: From: Gabriel Scherer Date: Thu, 10 Sep 2015 11:12:29 +0200 Message-ID: To: Martin DeMello Cc: OCaml List Content-Type: text/plain; charset=UTF-8 Subject: Re: [Caml-list] using a restricted subset of a polymorphic variant This works if you remove the restrictive annotation (x : dir) in the get_direction method, or replace it by the more flexible (x : [< dir]). The type [ `Down | `Up ] of heading is distinct from dir, but an instance of [< dir ]. On Thu, Sep 10, 2015 at 11:07 AM, Martin DeMello wrote: > I'm not sure exactly why this doesn't work: > > type dir = [`North | `South | `East | `West | `Up | `Down] > > let index = function > | `North -> 1 > | `South -> 2 > | `East -> 3 > | `West -> 4 > | `Up -> 5 > | `Down -> 6 > > class foo = object(self) > val mutable heading = `Up > > method flip_heading = > heading <- match heading with `Up -> `Down | `Down -> `Up > > method get_direction (x : dir) = index x > > method get_heading = self#get_direction heading > end > > it fails with > File "test.ml", line 28, characters 42-49: > Error: This expression has type [ `Down | `Up ] > but an expression was expected of type dir > The first variant type does not allow tag(s) > `East, `North, `South, `West > > but why is that an error? I'd think that any function that accepts type dir > should accept type [`Down | `Up] as well. Also, how do I get this to work? > > martin >