caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Olivier Andrieu" <oandrieu@nerim.net>
To: caml-list@inria.fr
Subject: Re: [Caml-list] phantom type thing question
Date: Thu, 1 Mar 2007 14:49:08 +0100	[thread overview]
Message-ID: <95513600703010549q3e1f8987k88315f9fd3189831@mail.gmail.com> (raw)
In-Reply-To: <95513600703010547t1f098d80p7bbff2f2c85d79a5@mail.gmail.com>

On 3/1/07, micha <micha-1@fantasymail.de> 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


  parent reply	other threads:[~2007-03-01 13:49 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-03-01  9:46 micha
     [not found] ` <95513600703010547t1f098d80p7bbff2f2c85d79a5@mail.gmail.com>
2007-03-01 13:49   ` Olivier Andrieu [this message]
2007-03-01 16:40   ` [Caml-list] " micha
2007-03-01 17:03     ` Olivier Andrieu
2007-03-01 20:01       ` micha

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=95513600703010549q3e1f8987k88315f9fd3189831@mail.gmail.com \
    --to=oandrieu@nerim.net \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).