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=1.0 required=5.0 tests=AWL,SPF_NEUTRAL autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id B309CBC0A for ; Thu, 1 Mar 2007 14:49:10 +0100 (CET) Received: from wr-out-0506.google.com (wr-out-0506.google.com [64.233.184.238]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l21Dn98l029862 for ; Thu, 1 Mar 2007 14:49:10 +0100 Received: by wr-out-0506.google.com with SMTP id i11so649463wra for ; Thu, 01 Mar 2007 05:49:08 -0800 (PST) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=HB6FiPYOneKVNwZYDzLwsdp2VljHnq/Y2CRzopkb46FC9BjpucDg1RNzcdebL6B6ET+MWhZ0HoEbIfj+tEdY08VGlbgK83WcBap4XWNcmUo0zVwr7qUpZQCALCF3UuUPyymAWc0KWyRPiQToAxt8mNOR10FdBWSx4pRaFORpFoI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:sender:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references:x-google-sender-auth; b=UovWsmN08V3gPtOXWWE+EZMHFkm+rpjpjphfjivSj+rWSjLuPB9Y656+3L3YwZrvVJ+tsZtyvhj3VH5N2aIUXdIX+fLWMDRhrjs1cq7zVoTxM1f+sW7/o6p4jFfdd8/hrRfQrETYL9+HZkSLYlzfvFxsRpH1AbZ51UPq3qZ+OYM= Received: by 10.114.107.19 with SMTP id f19mr1147544wac.1172756948332; Thu, 01 Mar 2007 05:49:08 -0800 (PST) Received: by 10.115.106.4 with HTTP; Thu, 1 Mar 2007 05:49:08 -0800 (PST) Message-ID: <95513600703010549q3e1f8987k88315f9fd3189831@mail.gmail.com> Date: Thu, 1 Mar 2007 14:49:08 +0100 From: "Olivier Andrieu" Sender: oandrieu@gmail.com To: caml-list@inria.fr Subject: Re: [Caml-list] phantom type thing question In-Reply-To: <95513600703010547t1f098d80p7bbff2f2c85d79a5@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <45E6A0E6.80502@fantasymail.de> <95513600703010547t1f098d80p7bbff2f2c85d79a5@mail.gmail.com> X-Google-Sender-Auth: 740d00759f3d1139 X-Miltered: at discorde with ID 45E6D9D5.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; andrieu:01 oandrieu:01 subtyping:01 variants:01 subtyping:01 annotation:01 -'a:01 params:01 params:01 val:01 val:01 polymorphic:01 wrote:01 abstract:01 caml-list:01 On 3/1/07, micha wrote: > > I'm getting confused while trying to implement some subtyping hierachy > with polymorphic variants. > say I have the hierachy: > > symbol -> image -> xpmimage > > and types like that: > > type 'a sym;; if you want subtyping, you'll need to add a variance annotation to your type parameter. Otherwise since your type sym is abstract, you'll get no subtyping at all. In this case you probably want a contravariant type parameter: type -'a sym > make_image: params -> [`Symbol | `Image] sym;; > make_xpm; params -> [`Symbol | `Image | `Xpm ] sym;; you can define type names, this gives shorter definitions for deep hierarchies: type symbol = [`Symbol] type image = [symbol | `Image] type xpm = [image | `Xpm] make_xpm : params -> xpm sym > so that some functions work only on some symbols: > > val get_image_width: [< `Image | `XpmImage] sym -> int;; > > I think I mix up the [< ..] and [> ... ] type constructs, allthough I > thought I understood it :-) that should be: val get_image_width : [> xpm] sym -> int -- Olivier