Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: vanicat@debian.org (Rémi Vanicat)
To: caml-list@inria.fr
Subject: Re: question about polymorphic variants
Date: Fri, 02 May 2008 20:03:18 +0200	[thread overview]
Message-ID: <87skx0shw9.dlv@maison.homelinux.org> (raw)
In-Reply-To: <f74178430805021035h60296fc7l133c23a222e41260@mail.gmail.com>

"Jacques Le Normand" <rathereasy@gmail.com> writes:

> Hello caml-list,
> when I try to run the following code:
>
>
> type sometype =
>   ([
>     `Foo of int
>   | `Bar of int
>   | `Var of 'a ref
>   ] as 'a)
> type someother =
>   ([
>     `Foo of int
>   | `Var of 'a ref
>   ] as 'a)
>
> let foo : someother = `Foo 5;;
> (foo :> sometype)
>
[...]
>
> how do I get around this?

this can't be done: ref type is neither co-variant or
contra-variant :

Imagine:

let foo : someother = `Var (ref Foo 10);;
let bar = (foo :> sometype);;
match bar with
| Var of r -> r:=`Bar 5;;
let baz = match foo with
| Var of r -> x

then baz will be of type someother, with the `Bar 5 value : this can't
be. So you cannot coerce a ref, and so you cannot coerce any value of
a type that include a ref.
-- 
Rémi Vanicat


  reply	other threads:[~2008-05-02 18:03 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-02 17:35 Jacques Le Normand
2008-05-02 18:03 ` Rémi Vanicat [this message]
  -- strict thread matches above, loose matches on Subject: below --
2005-10-28  9:57 Question " Xavier Clerc

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=87skx0shw9.dlv@maison.homelinux.org \
    --to=vanicat@debian.org \
    --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