From: Alain Frisch <alain@frisch.fr>
To: Jeremy Yallop <yallop@gmail.com>,
Dmitri Boulytchev <dboulytchev@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Confusing behaviour of type inference for polymorphic classes.
Date: Tue, 03 Dec 2013 09:35:00 +0100 [thread overview]
Message-ID: <529D97B4.9070108@frisch.fr> (raw)
In-Reply-To: <CAAxsn=Fs2s_fUuFM4tqq+EbdVo-Ofr_0X0ZezJLaXdg5GcEn_Q@mail.gmail.com>
On 12/02/2013 04:24 PM, Jeremy Yallop wrote:
> There's good news and bad news. The good news is that the problem can
> be solved for your particular example. The bad news is that the
> approach doesn't work in the general case.
A more general solution is based on recursive modules:
=======================================================================
type ('a, 'b) t =
A of 'a * ('b, 'a) t
| B of 'a
module rec X : sig
class ['a, 'b, 'ta, 'tb] m : object
method t : ('a -> 'ta) -> ('b -> 'tb) -> ('a, 'b) t -> ('ta, 'tb) t
end
end = struct
class ['a, 'b, 'ta, 'tb] m =
object
method t : ('a -> 'ta) -> ('b -> 'tb) -> ('a, 'b) t -> ('ta, 'tb) t =
fun fa fb s ->
match s with
| A (a, bat) -> A (fa a, (new X.m)#t fb fa bat)
| B a -> B (fa a)
end
end
=======================================================================
This technique also works e.g. for defining mutually recursive classes
and nominal types.
Alain
next prev parent reply other threads:[~2013-12-03 8:35 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-12-01 21:33 Dmitri Boulytchev
2013-12-02 14:41 ` Goswin von Brederlow
2013-12-02 15:05 ` Dmitri Boulytchev
2013-12-05 15:13 ` Goswin von Brederlow
2013-12-02 15:24 ` Jeremy Yallop
2013-12-03 8:35 ` Alain Frisch [this message]
2013-12-03 10:17 ` Jeremy Yallop
2013-12-03 12:33 ` Alain Frisch
2013-12-03 12:58 ` Jeremy Yallop
2013-12-03 17:49 ` Dmitri Boulytchev
2013-12-08 1:15 ` Jeremy Yallop
2013-12-09 13:48 ` Dmitri Boulytchev
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=529D97B4.9070108@frisch.fr \
--to=alain@frisch.fr \
--cc=caml-list@inria.fr \
--cc=dboulytchev@gmail.com \
--cc=yallop@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