caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Jeff Meister <nanaki@gmail.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Use-site variance in OCaml
Date: Wed, 12 Jun 2013 11:36:58 +0900	[thread overview]
Message-ID: <9A50D292-682E-48D6-9791-0CE1E733CDD0@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAHaHOqTqjHn4+tZqAszE0sYsXTdyLFr6s8FT=RhBvSjEGUgm1w@mail.gmail.com>

On 2013/06/12, at 5:58, Jeff Meister <nanaki@gmail.com> wrote:

> This seems like a good compromise! However, it raises another question for me. I tried writing ro/wo as modules rather than classes, but my variance annotations are not accepted then. Specifically, I cannot write:
> 
> module RO : sig
>   type +'a t
>   val get : 'a t -> 'a
> end = struct
>   type 'a t = 'a ref
>   let get x = !x
> end
> 
> Aside from the extensibility of class ro, this module looks like an equivalent definition. Yet I cannot declare 'a to be covariant, even though the type t is abstract, and the only operation on t given in the signature is covariant in 'a. Could the same behavior of class ro be allowed for module RO?
> 
> If so, then it seems like we could have a module-level definition like: module [type] RO = struct include module [type of] RW with type +'a t end
> 
> But even without adding that syntax, could the language allow me to manually decompose the module definition of RW into RO and WO?

Unfortunately, the way variance is computed for abstract types is very different of the one for objects.
Currently, for an abstract type to be covariant, its implementation must be covariant.
This problem was discussed in my paper on relaxing the value restriction.

It would be interesting to find a good criterion for  allowing this kind of variance improvement, and prove it.
Note that it can be tricky, as abstraction interacts in subtle ways with the rest of the language.
	Jacques Garrigue

      reply	other threads:[~2013-06-12  2:37 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-08  5:37 Jeff Meister
2013-06-08  7:05 ` Jacques Garrigue
2013-06-11 20:58   ` Jeff Meister
2013-06-12  2:36     ` Jacques Garrigue [this message]

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=9A50D292-682E-48D6-9791-0CE1E733CDD0@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=nanaki@gmail.com \
    /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).