Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: Jason Hickey <jyh@cs.caltech.edu>
To: caml-list@inria.fr
Cc: garrigue@math.nagoya-u.ac.jp
Subject: Re: [Caml-list] Pure visitor patterns
Date: Thu, 28 Dec 2006 00:06:54 -0800	[thread overview]
Message-ID: <B55E5E10-FEBB-41B3-BA05-E9435CCB8D32@cs.caltech.edu> (raw)
In-Reply-To: <d86ee07e0612272325g4209dfb5s8276f8b5e08ffd63@mail.gmail.com>

> On 12/27/06, Jacques Garrigue <garrigue@math.nagoya-u.ac.jp> wrote:
>> From: Jason Hickey <jyh@cs.caltech.edu>
>>
>> > Here are my questions:
>> >
>> >     - Why does 'a escape its scope in the recursive definition?
>>
>> Because during recursive definitions parameters of these definitions
>> are handled as monomorphic. So you cannot generalize the 'a locally.

Ah, that makes perfect sense.  If I understand correctly, the  
quantifiers in a mutual recursive class definition are hoisted, like  
this:

The definition
    class type ['a] c1 = ... and ['b] c2 = ...
is really more like the following (pardon my notation):
    ['a, 'b] (class type c1 = ... and c2 = ...)

The mistake is to think of it like simple recursive type definitions,  
like the following (rather useless) definition.

     type 'a visitor =
        { visit_foo : 'a -> foo -> 'a;
          visit_bar : 'a -> bar -> 'a
        }
     and foo = { accept : 'a. 'a -> 'a visitor -> 'a; examine : int }
     and bar = { accept : 'a. 'a -> 'a visitor -> 'a; examine : bool };;

I'm not complaining--the fact that you can write any of these types  
is very cool.

>> Another trick to make this pattern more scalable is to use  
>> constraints
>> for parameters.

Very good suggestion.  This makes it _much_ easier to deal with the  
multiplicity of types, since the constraints are linear, not  
quadratic, in the number of cases.

Many thanks for your explanation!

Jason

--
Jason Hickey                  http://www.cs.caltech.edu/~jyh
Caltech Computer Science      Tel: 626-395-6568 FAX: 626-792-4257




  parent reply	other threads:[~2006-12-28  8:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-12-27 19:31 Jason Hickey
2006-12-28  6:17 ` [Caml-list] " Jacques Garrigue
     [not found]   ` <d86ee07e0612272325g4209dfb5s8276f8b5e08ffd63@mail.gmail.com>
2006-12-28  8:06     ` Jason Hickey [this message]
2006-12-30 18:27   ` brogoff

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=B55E5E10-FEBB-41B3-BA05-E9435CCB8D32@cs.caltech.edu \
    --to=jyh@cs.caltech.edu \
    --cc=caml-list@inria.fr \
    --cc=garrigue@math.nagoya-u.ac.jp \
    /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