Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Alexey Egorov <electreg@list.ru>
Cc: OCaML List Mailing <caml-list@inria.fr>
Subject: Re: [Caml-list] CPS converting existential data type
Date: Sat, 20 Aug 2016 10:57:42 +0900	[thread overview]
Message-ID: <E1A14765-0B7F-4EBC-B21B-C3AD0F95FF2F@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <1471651332.586948056@f325.i.mail.ru>

On 2016/08/20 09:02, Alexey Egorov wrote:
> 
> Hello,
> 
> in haskell it's possible to convert some data type to it CPS'ed form using rank-N polymorphism.
> 
> I'm trying to do the same in ocaml using objects with polymorphic methods (instead of GHC RankNTypes extension), and it works well unless I'm using data type with existential type variables.
> 
> Example - https://gist.github.com/anonymous/57262e4e1009e658b97e8986a2d03d40 
> Haskell version compiles, while ocaml version gives type error about universal variable escaping it's scope.
> 
> What is the right way to do this? Is it possible at all?


The problem is that type annotations are not propagated to the body of objects, so you need to annotate the method explicitly, or to annotate the type of self.
The following annotated version works:

let uncps : type a . a cps_t -> a t =
  fun p -> p # get Nil (object
    method get : 'e . (a, 'e) d -> ('e -> a) -> a t = fun d f -> Cons (d, f)
  end)

Thank you for this interesting example.

Jacques Garrigue

  reply	other threads:[~2016-08-20  1:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-20  0:02 Alexey Egorov
2016-08-20  1:57 ` Jacques Garrigue [this message]
2016-08-21 12:35   ` Stephen Dolan

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=E1A14765-0B7F-4EBC-B21B-C3AD0F95FF2F@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=electreg@list.ru \
    /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