From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: "Milan Stanojević" <milanst@gmail.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] an issue with coercing private types
Date: Thu, 9 May 2013 12:53:00 +0900 [thread overview]
Message-ID: <42448548-6C1F-4008-AE02-6FD416FE7C32@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAKR7PS9fBVyBOutzTBw2n=ten55RP4n6Fb_8WQSkGZg71Z1BZw@mail.gmail.com>
On 2013/05/09, at 8:34, Milan Stanojević <milanst@gmail.com> wrote:
> I have this module
>
> module Foo : sig
> type 'a t = private int
> end = struct
> type 'a t = int
> end
>
> and then I want to coerce Foo.t into int
> let to_int (a : 'a Foo.t) = (a :> int)
>
> this fails to compile with
> Error: This expression cannot be coerced to type int; it has type 'a Foo.t
> but is here used with type int
>
> but this compiles fine
> let to_int a = (a : 'a Foo.t :> int)
>
> and gives me the right type.
The reason one works and not the other is explained here:
http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#toc76
Namely, when using single coercions from private type abbreviations,
the type of the expression should not contain type variables.
An interesting consequence is that the following is fine:
let to_int (type a) (a : a Foo.t) = (a :> int);;
Jacques Garrigue
prev parent reply other threads:[~2013-05-09 3:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-08 23:34 Milan Stanojević
2013-05-09 0:57 ` Markus Mottl
2013-05-09 2:26 ` Milan Stanojević
2013-05-09 3:53 ` 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=42448548-6C1F-4008-AE02-6FD416FE7C32@math.nagoya-u.ac.jp \
--to=garrigue@math.nagoya-u.ac.jp \
--cc=caml-list@inria.fr \
--cc=milanst@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).