Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Philippe Veber <philippe.veber@gmail.com>
To: caml users <caml-list@inria.fr>
Subject: [Caml-list] Typing of a parameterized class where the type parameter is the type of self.
Date: Thu, 30 Oct 2014 15:51:35 +0100	[thread overview]
Message-ID: <CAOOOohQ=KhAxx0jXZ9v1F1xfu-ddVXEz8O=oOqG7uo5O67FNSA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 969 bytes --]

Dear list,

I'm not sure why the following class definition is typed the way it is:

        OCaml version 4.02.1

# class type ['a] c = object ('a) method m : 'b end;;
class type ['a] c = object ('a) constraint 'a = < m : 'b. 'b; .. > method m
: 'b end

In particular I don't understand why the method m gets a polymorphic type.
This bites me when I try to specialize the type :

# type 'a t = (< m : int ; .. > as 'a) c;;
Error: This type < m : int; .. > should be an instance of type 'a c as 'a
Types for method m are incompatible

Instead of the type with polymorphic methods, I would have expected the
following type:

# class type ['a] c = object ('a) constraint 'a = < m : 'b; .. > method m :
'b end;;
class type ['a] c = object ('a) constraint 'a = < m : 'b; .. > method m :
'b end

And then have no problems doing what I wanted:

# type 'a t = (< m : int ; .. > as 'a) c;;
type 'a t = 'a constraint 'a = < m : int >

What did I get wrong?

Cheers,
  Philippe.

[-- Attachment #2: Type: text/html, Size: 1540 bytes --]

             reply	other threads:[~2014-10-30 14:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-10-30 14:51 Philippe Veber [this message]
2014-10-30 15:19 ` Leo White
2014-10-30 16:00   ` Philippe Veber
2014-10-30 16:07     ` Leo White
2014-10-30 16:13       ` Philippe Veber

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='CAOOOohQ=KhAxx0jXZ9v1F1xfu-ddVXEz8O=oOqG7uo5O67FNSA@mail.gmail.com' \
    --to=philippe.veber@gmail.com \
    --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