From: Dmitry Grebeniuk <gdsfh1@gmail.com>
To: Jacques Garrigue <caml-list@inria.fr>
Subject: Re: [Caml-list] recursive module, object types, tying knot
Date: Fri, 9 Sep 2011 14:14:17 +0300 [thread overview]
Message-ID: <CAPi0vKWEMh=5PmA1ekpbOMqcEpkGBEzo-LkoCAXd-5cqmusY+w@mail.gmail.com> (raw)
In-Reply-To: <14203FCD-811F-41CC-A0D7-5A360D4815CA@math.nagoya-u.ac.jp>
Hello.
>> Error: This type scheme cannot quantify 'b :
>> it escapes this scope.
> The answer is unfortunately short: there is no solution.
Thank you for the definitive and quick answer!
> Namely recursive types in ocaml must be regular.
> I.e., they must expand to a finite graph.
> In particular this means that, inside the class lst, all occurences
> of lst must have exactly the parameter 'a.
Just interesting: where this graph and its finiteness property
are used?
> As you have already found, you can avoid this problem by
> defining a record which "hides" the use of lst.
> Namely, you must break the cycle with a datatype,
> either record or sum type.
> Unfortunately this also means that this type has to belong
> to some module, and you also lose subtyping.
I've tried to make the type (lst 'b) belong to some first-class
module returned by some method call (to object with type
lst 'a), but without any success.
And while playing with first-class modules I've noted that
I can't constrain the parametric type of module:
let module M = (lst#mapmodule : Mappable with type t 'a = list a)
-- one more way is blocked (but don't know was it the way
really).
But I can reformulate (and maybe make easier) my task:
I can move the code that work with different type parameters
(lst 'a -> lst 'b) to simple functions. For example, "map" for
containers -- to the function like "container_map", which
will work with containers (objects that have some methods),
to make the code work:
container_map func (new lst [1;2;3]);
container_map func (new arr [|1;2;3|]).
I understand that the imaginable "container_map" function
should require some method with some type, that can
give me the value of type lst 'b for lst 'a in case of lists,
and the value of type arr 'b for arr 'a in case of arrays,
but I can't write such type (even with first-class modules).
Is it impossible too?
next prev parent reply other threads:[~2011-09-09 11:14 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-09-07 21:29 Dmitry Grebeniuk
2011-09-07 21:44 ` Jacques Garrigue
2011-09-09 11:14 ` Dmitry Grebeniuk [this message]
2011-09-09 13:50 ` Jacques Garrigue
2011-09-13 4:56 ` Dmitry Grebeniuk
2011-09-13 7:22 ` Gabriel Scherer
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='CAPi0vKWEMh=5PmA1ekpbOMqcEpkGBEzo-LkoCAXd-5cqmusY+w@mail.gmail.com' \
--to=gdsfh1@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