From: Jacques Carette <carette@mcmaster.ca>
To: bob zhang <bobzhang1988@gmail.com>
Cc: Caml List <caml-list@inria.fr>
Subject: Re: [Caml-list] Polymorphic Variants for big Ast?
Date: Thu, 04 Oct 2012 23:19:34 -0400 [thread overview]
Message-ID: <506E51C6.6070607@mcmaster.ca> (raw)
In-Reply-To: <CANcqPu4H77snPXMf9J0-f5NcCoKTw_=0u5LqMZuVUe_54aeMNA@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1424 bytes --]
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.
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.
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
[-- Attachment #2: Type: text/html, Size: 2271 bytes --]
next prev parent reply other threads:[~2012-10-05 3:21 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 [this message]
2012-10-05 3:38 ` bob zhang
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=506E51C6.6070607@mcmaster.ca \
--to=carette@mcmaster.ca \
--cc=bobzhang1988@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