caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: bob zhang <bobzhang1988@gmail.com>
To: Jacques Carette <carette@mcmaster.ca>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Polymorphic Variants for big Ast?
Date: Thu, 4 Oct 2012 23:38:57 -0400	[thread overview]
Message-ID: <CANcqPu62z=sOu6L3nYMJ-3pcibUsYNTU2dE_VVoUzQikA2i-fg@mail.gmail.com> (raw)
In-Reply-To: <506E51C6.6070607@mcmaster.ca>

[-- Attachment #1: Type: text/plain, Size: 2216 bytes --]

Greetings,

On Thu, Oct 4, 2012 at 11:19 PM, Jacques Carette <carette@mcmaster.ca>wrote:

>  On 04/10/2012 7:15 PM, bob zhang wrote:
>
>    Has anyone have the experience using polymorphic variant for a big
> Ast?
>   The benefit I can think of is  open recursion, global namespace(not in a
> module). Did anyone give a try?
>
>
> I have -- mostly because I needed subtying, since the language I was
> modelling had a kind of subtyping that polymorphic variants could track
> 'for free'.
>
> It works.  But it can be a real pain too: depending on your use cases, you
> may need a fair amount of annotations (casts).  And if you make a mistake,
> the error messages are truly frightening, especially when you have an AST
> with 4 mutually recursive parts, totaling about 25 cases, and the mistake
> is 3 or 4 levels deep -- the error messages can go on for pages and pages.
> Buried in there will be the information you need to fix the mistake, but
> finding it can be extremely challenging.
>
> Thanks for your warning,  that's really helpful

> I would say: use it only if you really really need what polymorphic
> variants 'buy' you, else stay away.  In my original code, I have rewritten
> most of it to use normal variants (except for one case) and use explicit
> open recursion (i.e. extra type variable + tying the knot) to get the job
> done.  The error messages are sane now.
>
> I am considering change Camlp4 Ast node into  Polymorphic Variants(I know
it's hard, suppose I could make it) The problem with normal Algebraic Data
Type to me is that I have to use functors to abstract over types, and
functors are really intrusive, you need to write a large amount of
signatures everywhere.

To make things much worse, * the ADT depends on the qualified module
names *which
makes the bootstrapping system fragile. So I think polymorphic variant may
fit this area nicely.
   As you said, the error message is something I worried about. How about
performance issues?

> Note that I don't think the error messages were incorrect in any way (I am
> sure they were not).  It might have been possible to have made them
> friendlier / more precise, but I am not even sure of that.
>
> Jacques
>



-- 
Regards
-- Bob

[-- Attachment #2: Type: text/html, Size: 3499 bytes --]

  reply	other threads:[~2012-10-05  3:39 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-04 23:15 bob zhang
2012-10-05  3:19 ` Jacques Carette
2012-10-05  3:38   ` bob zhang [this message]
2012-10-05 11:33     ` David Rajchenbach-Teller
2012-10-05  7:51 ` Pierre-Alexandre Voye

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='CANcqPu62z=sOu6L3nYMJ-3pcibUsYNTU2dE_VVoUzQikA2i-fg@mail.gmail.com' \
    --to=bobzhang1988@gmail.com \
    --cc=caml-list@inria.fr \
    --cc=carette@mcmaster.ca \
    /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).