caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Mark Shinwell" <mshinwell@janestcapital.com>
To: Julien SIGNOLES <julien.signoles@cea.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Caml implementation of the relaxed value restriction
Date: Wed, 14 Jan 2009 15:52:50 +0000	[thread overview]
Message-ID: <20090114155250.GJ28444@janestcapital.com> (raw)
In-Reply-To: <1231947084.7199.34.camel@localhost>

On Wed, Jan 14, 2009 at 04:31:24PM +0100, Julien SIGNOLES wrote:
> In the article "Many Holes in Hindley-Milner" [1], Sam Lindley claims
> that the type of x is ('a * 'a s, int) NList.t in the following ocaml
> program because of Garrigue's relaxed value restriction [2].
> ==========
> type 'a s
> 
> module NList : sig
>   type (+'length, +'elem_type) t
>   val nil : ('m*'m, 'a) t
>   val cons: 'a * ('m*'n, 'a) t -> ('m*'n s,'a) t
> end = struct
>   type ('i,'a) t = 'a list
>   let nil = []
>   let cons (x, l) = x :: l
> end
> 
> let x = NList.cons (1, NList.nil)
> ==========
> 
> But, both with ocaml v3.10.2 and ocaml v3.12.0+dev1 (2008-12-03) (that
> is the current cvs version), the infered type of [x] only contains a
> weak type variable: ('_a * '_a s, int) NList.t.
> 
> I quickly look at the typing rules introduced by Jacques Garrigue in [2]
> and it seems to me that Sam Lindley is right: [x] is generalisable in
> the above program.
> 
> So, what's wrong here?

You need to say "type +'a s", otherwise the compiler (since "s" is an
abstract type) cannot know the variance of that type parameter inside a
value of type 'a s.  That information is needed to determine how to
generalize the type of x.

Mark


      reply	other threads:[~2009-01-14 15:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-01-14 15:31 Julien SIGNOLES
2009-01-14 15:52 ` Mark Shinwell [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=20090114155250.GJ28444@janestcapital.com \
    --to=mshinwell@janestcapital.com \
    --cc=caml-list@inria.fr \
    --cc=julien.signoles@cea.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).