From: Dmitri Boulytchev <dboulytchev@gmail.com>
To: Jeremy Yallop <yallop@gmail.com>, Alain Frisch <alain@frisch.fr>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Confusing behaviour of type inference for polymorphic classes.
Date: Tue, 03 Dec 2013 21:49:03 +0400 [thread overview]
Message-ID: <529E198F.7060704@gmail.com> (raw)
In-Reply-To: <CAAxsn=GKbz4SMoJ+5_9r0ZCOA=-1kGsjgD0d3_7DUdxP4_5BEw@mail.gmail.com>
Jeremy, Alain,
the code snippet I presented was actually boiled down from the more
complex example.
I don't have any particular interest to the concrete type t; I'm ok to
give up
on "finitely regularizable" types but I definitely don't want to give up
on GADTs
which might be essentially irregular.
> As you've noted, you can work around the
> problem using open recursion and typing the knot yourself, but you
> lose the ability to subtype in the process.
Well, having the solution with the polymorphic recursive function
class ['a, 'b, 'ta, 'tb] proto_m f =
object ... end
let rec f : 'a 'b 'ta 'tb . unit -> ('a, 'b, 'ta, 'tb) #proto_m =
fun () -> new proto_m f
class ['a, 'b, 'ta, 'tb] m = ['a, 'b, 'ta, 'tb] proto_m f
it is possible to inherit from proto_m:
class ['a, 'b, 'ta, 'tb] m' f =
object
inherit ['a, 'b, 'ta, 'tb] proto_m f as super
method t fa fb s =
match s with
| A (a, bat) -> <some extra work>; super#t fa fb s
| B a -> <some extra work>; super#t fa fb s
end
let rec g : 'a 'b 'ta 'tb . unit -> ('a, 'b, 'ta, 'tb) #proto_m =
fun () -> new m' g
class ['a, 'b, 'ta, 'tb] subm = ['a, 'b, 'ta, 'tb] m' g
Here subm is a legitimate subclass of m with the desired behaviour
(this property can not be
achieved with the recursive module though it is really much more elegant
way to provide the proper
instantiation for class type parameters). So I don't see why I'm loosing
the ability to subtype.
It seems to me that this workaround can be used to overcome the "regular
class" restriction
completely in a syntax-conversion manner. I appreciate any comments.
Dmitry.
next prev parent reply other threads:[~2013-12-03 17:49 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
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 [this message]
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=529E198F.7060704@gmail.com \
--to=dboulytchev@gmail.com \
--cc=alain@frisch.fr \
--cc=caml-list@inria.fr \
--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