From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail1-relais-roc.national.inria.fr (mail1-relais-roc.national.inria.fr [192.134.164.82]) by sympa.inria.fr (Postfix) with ESMTPS id 146B97EDD8 for ; Fri, 5 Oct 2012 05:39:00 +0200 (CEST) Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of bobzhang1988@gmail.com) identity=pra; client-ip=209.85.223.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="bobzhang1988@gmail.com"; x-sender="bobzhang1988@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail1-smtp-roc.national.inria.fr: domain of bobzhang1988@gmail.com designates 209.85.223.182 as permitted sender) identity=mailfrom; client-ip=209.85.223.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="bobzhang1988@gmail.com"; x-sender="bobzhang1988@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail1-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ie0-f182.google.com) identity=helo; client-ip=209.85.223.182; receiver=mail1-smtp-roc.national.inria.fr; envelope-from="bobzhang1988@gmail.com"; x-sender="postmaster@mail-ie0-f182.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArUBAEVVblDRVd+2m2dsb2JhbABFgku8SwgjAQEBAQEICQsJFCeCIAEBAQMBEgIsARsdAQMBCwYFCw0uIgERAQUBHAYTIodQAQMJBpoACQOMJYJ1hQQKGScNWYh1AQUMizKGCQOVaY5NFimEKQ X-IronPort-AV: E=Sophos;i="4.80,538,1344204000"; d="scan'208";a="175901011" Received: from mail-ie0-f182.google.com ([209.85.223.182]) by mail1-smtp-roc.national.inria.fr with ESMTP/TLS/RC4-SHA; 05 Oct 2012 05:38:59 +0200 Received: by mail-ie0-f182.google.com with SMTP id k10so4615920iea.27 for ; Thu, 04 Oct 2012 20:38:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=XaaK9gdnYMmX0/91TbuYgLeOZo/AG0fAQ+sxlozB4jg=; b=ecBTl4N4iyIFS8oGLkZ332KE1UZWxHeDU3ShBtQSx/jueR8lNmOdt8hx4R9dQGcS4l etl7odUTgIEkc3I3gUQQvX0C2usmA/+SZNyMNgy8Xd+98DNP9QCrGawZKM+bz1XeOBgU A2NIPgfJtWa7maX33Y8cmckvWgevp989bz8QzK0CBKb2wEscP6GYWAj7L57QeenzBLMO sP0SN3cqZLzUEX1MgIq+vvtASZOwWIeqsLndMifwYgSgL6spmsVrZdh6yWbjCe/jo/VU tU0fZlgvR0RMQy5eMEG3iiMxSLBpXlc6askt6fWhO0BqGQA7RMcZjf14bdYh5b2KUZ+k /9mA== MIME-Version: 1.0 Received: by 10.50.160.165 with SMTP id xl5mr68262igb.0.1349408338049; Thu, 04 Oct 2012 20:38:58 -0700 (PDT) Received: by 10.64.17.4 with HTTP; Thu, 4 Oct 2012 20:38:57 -0700 (PDT) In-Reply-To: <506E51C6.6070607@mcmaster.ca> References: <506E51C6.6070607@mcmaster.ca> Date: Thu, 4 Oct 2012 23:38:57 -0400 Message-ID: From: bob zhang To: Jacques Carette Cc: Caml List Content-Type: multipart/alternative; boundary=14dae9340efda57ad604cb479c8e Subject: Re: [Caml-list] Polymorphic Variants for big Ast? --14dae9340efda57ad604cb479c8e Content-Type: text/plain; charset=ISO-8859-1 Greetings, On Thu, Oct 4, 2012 at 11:19 PM, Jacques Carette 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 --14dae9340efda57ad604cb479c8e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Greetings,

On Thu, Oct 4, 2012 at 11:19 P= M, Jacques Carette <carette@mcmaster.ca> wrote:
=20=20 =20=20=20=20 =20=20
On 04/10/2012 7:15 PM, bob zhang wrote:
=A0=A0 Has anyone have the experience using polymorphic variant for a big Ast?=A0
=A0 The benefit I can think of is =A0open 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.=A0 But it can be a real pain too: depending on your use cases, you may need a fair amount of annotations (casts).=A0 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.=A0 Buried in there will be the information you need to fix the mistake, but finding it can be extremely challenging.

Thanks for your warning, =A0that's real= ly helpful=A0
I would say: use it only if you really really need what polymorphic variants 'buy' you, else stay away.=A0 In my original code, I h= ave 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.=A0 The error messages are sane now.

I am considering change Camlp4 Ast node int= o =A0Polymorphic Variants(I know it's hard, suppose I could make it)=A0= The problem with normal Algebraic Data Type to me is that I have to use fun= ctors to abstract over types, and functors are really intrusive, you need t= o write a large amount of signatures everywhere.

To make things much worse, =A0the ADT depends on the= qualified module names which makes the bootstrapping system fragile. S= o I think polymorphic variant may fit this area nicely.=A0
=A0 = =A0As you said, the error message is something I worried about. How about p= erformance issues?
Note that I don't think the error messages were incorrect in any way (I am sure they were not).=A0 It might have been possible to have made them friendlier / more precise, but I am not even sure of that.=A0
=
Jacques



--
Regards=
-- Bob
--14dae9340efda57ad604cb479c8e--