From: Jerome Vouillon <jerome.vouillon@inria.fr>
To: Frederic Tronel <Frederic.Tronel@inrialpes.fr>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Recursive classes and subtyping
Date: Fri, 1 Feb 2002 14:34:48 +0100 [thread overview]
Message-ID: <20020201143448.A16091@pauillac.inria.fr> (raw)
In-Reply-To: <3C5A8747.BE14426@inrialpes.fr>; from Frederic.Tronel@inrialpes.fr on Fri, Feb 01, 2002 at 01:17:11PM +0100
Hello,
> Why is it that these classes definitions are not accepted by
> the compiler :
>
> class a =
[...]
> and b =
> object (this)
[...]
> initializer this#set_al [(c :> a)]
> end
> and c =
[...]
>
> while these ones can be compiled:
>
> class a =
[...]
> class c =
[...]
> class b =
> object (this)
[...]
> initializer this#set_al [(c :> a)]
> end
>
> Where is the fundamental difference ????
In the first case, the type "a" is not fully known when the coercion
"(c :> a)" is performed, as the classes are mutually recursive. The
compiler handles this case as if it knew nothing about the structure
of the type "a". With this assumption, the only case the compiler can
be sure that the type of "c" is a subtype of "a" is when the type of
"c" is "a". This is not the case, hence the error message.
The reason for this overly conservative (in this case) assumption is
that the result of the type inference algorithm could otherwise depend
on the order in which the program is typed.
If you really need mutually recursive classes, a work-around is to
explicitely define the classe types before defining the classes.
-- Jérôme
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next prev parent reply other threads:[~2002-02-01 13:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-02-01 12:17 Frederic Tronel
2002-02-01 13:34 ` Jerome Vouillon [this message]
2002-02-01 13:42 ` Frederic Tronel
2002-02-01 14:55 ` Claudio Sacerdoti Coen
2002-02-01 15:12 ` Claudio Sacerdoti Coen
2002-02-01 16:41 ` Laurent Vibert
2002-02-01 17:01 ` Claudio Sacerdoti Coen
2002-02-01 17:20 ` Claudio Sacerdoti Coen
2002-02-04 2:30 ` Jacques Garrigue
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=20020201143448.A16091@pauillac.inria.fr \
--to=jerome.vouillon@inria.fr \
--cc=Frederic.Tronel@inrialpes.fr \
--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