caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques Garrigue <garrigue@math.nagoya-u.ac.jp>
To: Philippe Veber <philippe.veber@gmail.com>
Cc: OCaml Mailing List <caml-list@inria.fr>
Subject: Re: [Caml-list] Unwanted type constraint in mutually recursive parameterized class type definition.
Date: Thu, 9 Jul 2015 08:57:50 +0900	[thread overview]
Message-ID: <10510894-97DB-4DA9-8334-F02C11E94504@math.nagoya-u.ac.jp> (raw)
In-Reply-To: <CAOOOohSwhQ7GwHHh--VJ0A4uKOVpqn8NzCUhW-5E3BkX5PGV6Q@mail.gmail.com>

On 2015/07/09 01:24, Philippe Veber wrote:
> 
> Dear camlers,
> 
>   I obtain an unexpected answer from the toplevel when I enter the following definition:
> 
>         OCaml version 4.03.0+dev7-2015-02-08
> 
> # class type ['a] c =
>   object
>     method m : d
>   end
> and d =
>   object
>     inherit [int] c
>   end
> ;;
> class type ['a] c = object constraint 'a = int method m : d end
> and d = object method m : d end
> 
> What surprises me is the constraint 'a = int in the definition of c. Is this is a bug or feature?


This is a feature (or at least, the intended behavior)
For classes, type constraints are inferred automatically, but in a monomorphic way.
A standard workaround is to open the recursion by generalizing definitions:

class type ['a,'d] c0 = object method m : 'd end
class type d = object inherit ['a,d] c0 end
class type ['a] c = ['a,d] c0

Jacques Garrigue

  reply	other threads:[~2015-07-08 23:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-08 16:24 Philippe Veber
2015-07-08 23:57 ` Jacques Garrigue [this message]
2015-07-16 16:00   ` 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=10510894-97DB-4DA9-8334-F02C11E94504@math.nagoya-u.ac.jp \
    --to=garrigue@math.nagoya-u.ac.jp \
    --cc=caml-list@inria.fr \
    --cc=philippe.veber@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).