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 0861E7F1AA for ; Thu, 10 Sep 2015 11:13:27 +0200 (CEST) IronPort-PHdr: 9a23:WA3Uqx+hlD611v9uRHKM819IXTAuvvDOBiVQ1KB92+0cTK2v8tzYMVDF4r011RmSDdmdsq4MotGVmp6jcFRI2YyGvnEGfc4EfD4+ouJSoTYdBtWYA1bwNv/gYn9yNs1DUFh44yPzahANS47AblHf6ke/8SQVUk2mc1EleqKsRsb7tIee6aObw9XreQJGhT6wM/tZDS6dikHvjPQQmpZoMa0ryxHE8TNicuVSwn50dxrIx06vru/5xpNo8jxRtvQ97IYAFPyiJ+VrBYBfWREvKXw04oXHuDzOSQ+Iri8ZW38KkxxEDg3I6BX9dpj0uyr+8OF63X/JE9fxSOUfWS6j9LtsUB/fqLkIOiRxpGrXkM1rkKVDoFShoBFwzpT8fJzQPvdkeqLbO98XEzkSFv1NXjBMV9vvJ7AECPAMaKMB99Hw Authentication-Results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=christoph.hoeger@tu-berlin.de; spf=None smtp.mailfrom=christoph.hoeger@tu-berlin.de; spf=None smtp.helo=postmaster@mail.tu-berlin.de Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of christoph.hoeger@tu-berlin.de) identity=pra; client-ip=130.149.7.33; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="christoph.hoeger@tu-berlin.de"; x-sender="christoph.hoeger@tu-berlin.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of christoph.hoeger@tu-berlin.de) identity=mailfrom; client-ip=130.149.7.33; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="christoph.hoeger@tu-berlin.de"; x-sender="christoph.hoeger@tu-berlin.de"; x-conformance=sidf_compatible Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail.tu-berlin.de) identity=helo; client-ip=130.149.7.33; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="christoph.hoeger@tu-berlin.de"; x-sender="postmaster@mail.tu-berlin.de"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0BYAQB+SPFVnCEHlYJdg3dpgya8AIYBAoE/PBABAQEBAQEBARABAQEBAQgLCQkhLoIdggcBAQQjBAsBRQEQCxoCBRYLAgIJAwIBAgFFBg0GAgEBiCoEtwOUGwEBAQEGAiCBIopMhFkzB4JpgUMFlVaFCooChmaSADiELW+ISQEBAQ X-IPAS-Result: A0BYAQB+SPFVnCEHlYJdg3dpgya8AIYBAoE/PBABAQEBAQEBARABAQEBAQgLCQkhLoIdggcBAQQjBAsBRQEQCxoCBRYLAgIJAwIBAgFFBg0GAgEBiCoEtwOUGwEBAQEGAiCBIopMhFkzB4JpgUMFlVaFCooChmaSADiELW+ISQEBAQ X-IronPort-AV: E=Sophos;i="5.17,503,1437429600"; d="scan'208";a="176812687" Received: from mail.tu-berlin.de ([130.149.7.33]) by mail2-smtp-roc.national.inria.fr with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 10 Sep 2015 11:13:26 +0200 X-tubIT-Incoming-IP: 91.64.68.238 Received: from ip5b4044ee.dynamic.kabel-deutschland.de ([91.64.68.238] helo=[192.168.178.42]) by mail.tu-berlin.de (exim-4.76/mailfrontend-7) with esmtpsa [UNKNOWN:AES128-SHA:128] id 1ZZxv2-0006Ku-2P; Thu, 10 Sep 2015 11:13:25 +0200 To: Martin DeMello References: Cc: caml users From: =?UTF-8?Q?Christoph_H=c3=b6ger?= Organization: =?UTF-8?Q?Technische_Universit=c3=a4t_Berlin?= Message-ID: <55F149B4.3060909@tu-berlin.de> Date: Thu, 10 Sep 2015 11:13:24 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.2.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-PMX-Version: 6.0.0.2142326, Antispam-Engine: 2.7.2.2107409, Antispam-Data: 2015.9.10.90617 X-PMX-Spam: Gauge=IIIIIII, Probability=0%, Report='' Subject: Re: [Caml-list] using a restricted subset of a polymorphic variant You explicitly ask for an argument of type dir, but you want to ask for an argument of any subtype of dir: method get_direction (x : [< dir]) regards, Christoph Am 10.09.2015 um 11:07 schrieb Martin DeMello: > 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 > -- Christoph Höger Technische Universität Berlin Fakultät IV - Elektrotechnik und Informatik Übersetzerbau und Programmiersprachen Sekr. TEL12-2, Ernst-Reuter-Platz 7, 10587 Berlin Tel.: +49 (30) 314-24890 E-Mail: christoph.hoeger@tu-berlin.de