caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Mauricio Fernandez <mfp@acm.org>
To: caml-list@inria.fr
Subject: Re: [Caml-list] polymorphic variants and recursive functions
Date: Thu, 26 Mar 2009 00:24:38 +0100	[thread overview]
Message-ID: <20090325232438.GW8986@NANA.localdomain> (raw)
In-Reply-To: <CA29810E-1260-4571-87FA-96C71F62C065@gmail.com>

On Wed, Mar 25, 2009 at 02:39:28PM -0700, Warren Harris wrote:
> let rec eval = function
>   | `Arr v -> (eval_arr v : [`V] Lwt.t    :> [> `V] Lwt.t)
>   | `Obj v -> (eval_obj v : [`V|`O] Lwt.t :> [> `V] Lwt.t)
> and eval_arr v = eval_obj v >>= arr
> and eval_obj v = eval v >>= obj
>
>     | `Obj v -> (eval_obj v : [`V|`O] Lwt.t :> [> `V] Lwt.t)
>                  ^^^^^^^^^^
> This expression has type [ `O | `V ] Lwt.t but is here used with type
>   [ `V ] Lwt.t
> The second variant type does not allow tag(s) `O

The Lwt.t type is abstract and invariant since no annotation has been given
for the type variable (you'd need it to be  type +'a t):

# let a : [`O] Lwt.t = return `O;;
val a : [ `O ] Lwt.t = <abstr>
# (a :> [`O | `V] Lwt.t);;
Error: Type [ `O ] Lwt.t is not a subtype of type [ `O | `V ] Lwt.t 
The first variant type does not allow tag(s) `V

In your example, [> `V] Lwt.t  in the second line becomes 
   [`V] Lwt.t,
(the type variable is not covariant) and you cannot do  
   [`V | `O] Lwt.t :> [`V] Lwt.t
in the third line.

Unfortunately, the type variable is in both variant and contravariant position
in the definition of Lwt.t...

-- 
Mauricio Fernandez  -   http://eigenclass.org


  reply	other threads:[~2009-03-25 23:24 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-25 21:39 Warren Harris
2009-03-25 23:24 ` Mauricio Fernandez [this message]
2009-03-26  0:06   ` [Caml-list] polymorphic variants and recursive functions (caml: to exclusive) Warren Harris

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=20090325232438.GW8986@NANA.localdomain \
    --to=mfp@acm.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;
as well as URLs for NNTP newsgroup(s).