caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Dmitri Boulytchev <dboulytchev@gmail.com>
To: Jeremy Yallop <yallop@gmail.com>
Cc: caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Confusing behaviour of type inference for polymorphic classes.
Date: Mon, 09 Dec 2013 17:48:08 +0400	[thread overview]
Message-ID: <52A5CA18.1070408@gmail.com> (raw)
In-Reply-To: <CAAxsn=EmYQjqOn1psUsZGUqRc2=SfR4F+Dk7kKqZFAzCAf=OoQ@mail.gmail.com>


> Yes, it's a neat approach!  One small suggestion: in order to handle
> the case where the type you're traversing has multiple recursive
> instantations with different parameters you might consider passing the
> instance creation function in a way that allows it to be called
> polymorphically (e.g. by wrapping it in a record with a polymorphic
> field):
     Of course; this is yet another workaround to make it possible to use
that workaround :)

> There is one last thing I'm curious about.  The difficulties that
> you're avoiding with open recursion seem to arise from the
> representation of the traversal as a parameterised class with a
> monomorphic method.
     The reason is quite simple --- class parameters are used to represent
the *result* type of the transformation, not the parameters of the 
transforming
type. I simplified the example just to clarify the polymorphic class issues.
     In reality what I'm interested in is somewhat like this: for a type

     ('a, 'b, ...) t = A ... | B ... | C ...

     we generate a virtual class

     class virtual ['ta, 'tb, ..., 'inh, 'syn] t_t = object
         method virtual c_A : <explicitly polymorphic type on 'a, 'b etc.>
         method virtual c_B : <explicitly polymorphic type on 'a, 'b etc.>
         etc.
     end

     which represents some attribute transformation with inherited 
attribute type 'inh; the
type of synthesized attribute for type 'a is 'ta, for 'b is 'tb etc., 
for type ('a, 'b, ...) t
is 'syn. The methods of the class handle the individual constructors; 
the arguments for
these methods capture the transformation function as well.
     For example, for regular map we have the following bindings:

     class ['ta, 'tb, ...] map_t = object
         inherit ['ta, 'tb, ..., unit, ('ta, 'tb, ...) t] t_t
         ...
     end

     for show we have

     class show_t = object
         inherit [string, string, ..., unit, string] t_t
         ...
     end

     for, say, eval

     class eval_t = object
         inherit [int, int, ..., string -> int, int] t_t
         ...
     end

     etc.

     Under this representation we might need the single 
shallow-traversal generic function
to implement all these transformations.
     Per-constructor object encoding allows modification with less 
boilerplate code (via
inhertance); in addition if we have a polymorphic-variant type t = [ a | 
b | c ... ] then
the certain transformation for t can be constructed by regular class 
inheritance from the
implementations of the same transformation for it's counterparts.


     Best regards,
     Dmitry.

     P.S. I was'nt offended by your long message (but surprised a little 
bit ).

      reply	other threads:[~2013-12-09 13:48 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
2013-12-08  1:15             ` Jeremy Yallop
2013-12-09 13:48               ` Dmitri Boulytchev [this message]

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=52A5CA18.1070408@gmail.com \
    --to=dboulytchev@gmail.com \
    --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;
as well as URLs for NNTP newsgroup(s).