From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by sympa.inria.fr (Postfix) with ESMTPS id BA5277EEAF for ; Mon, 21 Jan 2013 06:29:57 +0100 (CET) Received-SPF: None (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of bobzhang1988@gmail.com) identity=pra; client-ip=209.85.223.172; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="bobzhang1988@gmail.com"; x-sender="bobzhang1988@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail4-smtp-sop.national.inria.fr: domain of bobzhang1988@gmail.com designates 209.85.223.172 as permitted sender) identity=mailfrom; client-ip=209.85.223.172; receiver=mail4-smtp-sop.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 (mail4-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-ie0-f172.google.com) identity=helo; client-ip=209.85.223.172; receiver=mail4-smtp-sop.national.inria.fr; envelope-from="bobzhang1988@gmail.com"; x-sender="postmaster@mail-ie0-f172.google.com"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ArQBAOnP/FDRVd+sm2dsb2JhbABEvjAIFg4BAQEBAQgJCwkUJ4JlARsYBgMSEF0BEQEFASKIGQEDD5s5gnCMNIJ7g3IKGScNWYgFAQUMkS0DiGGNK4EcjUwWKYQ1 X-IronPort-AV: E=Sophos;i="4.84,504,1355094000"; d="scan'208";a="169142093" Received: from mail-ie0-f172.google.com ([209.85.223.172]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 21 Jan 2013 06:29:56 +0100 Received: by mail-ie0-f172.google.com with SMTP id c13so9274146ieb.3 for ; Sun, 20 Jan 2013 21:29:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type; bh=8Lwu80EgnbvWb+ysTOI1/IJ7BHFD3oSwInsatoNY0Z8=; b=eGuMHVd3YMNlZ9Mg3uYmg+2CdZi2QKmpLcgA9sstCFxIL9WBUswjiG1fYG3NStxlQI eHo+DHP1Slm6uZU05hLbp0de+FyxSWWOhVLyGJoYCoqCrby0M7DpdEfg2xsnKARMQFkx 1bkW8EaWKJoWBK3YuqEuWGtKBwgIjK6Zj8MwxIVftbMXvYLaknf/tdhye//JPgnLTZQy HR1TDFoOihOUsqSuFAwD6FEs8TbnKqN49tBHcdboedforh9ny7eOaTJg4tvOr5ypfLgz 5cxcep1BHK/nopDn0ono8/32Z/RXY66DYZWO4c69PFyvgn9NyCdQGeoi/jX7j41OeidS BsKQ== MIME-Version: 1.0 X-Received: by 10.50.173.33 with SMTP id bh1mr8058781igc.41.1358746195687; Sun, 20 Jan 2013 21:29:55 -0800 (PST) Received: by 10.64.17.4 with HTTP; Sun, 20 Jan 2013 21:29:55 -0800 (PST) Date: Mon, 21 Jan 2013 00:29:55 -0500 Message-ID: From: bob zhang To: Caml List Content-Type: text/plain; charset=ISO-8859-1 Subject: [Caml-list] Fan, a promising replacement of camlp4 Dear Camlers, Fan (https://github.com/bobzhang/Fan) is a dialect of ocaml for meta-programming, though it's still under active development, but I think I have done something right, so I would be happy to share some encouraging results. Besides the engineering part(Fan is much much faster than camlp[4,5], with numerous bug fixes, nested quotation-antiquotation, pluggable lexer, etc), the main contribution lies in 3 parts: First, Fan uses polymorphic variants to encode the intermediate Ast; Second, Fan supports first class programmable grammar/lexer, Third, Fan has a strong built in customizable deriving support. First. variants hit the sweet spot here, (don't worry about the error message, since we provide a quasi-quotation mechanism, so for a large ast, the user don't construct the Ast by hand). The benefit is *huge*, a. shared constructor branches A lot of code re-use and much cleaner API here, think about if you need a function which takes the location from the Ast node, in Camlp4, you have to write loc_of_expr or loc_of_patt, to make things worse, once you choose loc_of_expr, the function can only apply to expr, no code re-use anymore, now in Fan, you only need loc_of, it can apply to all syntax categories, (btw, loc_of is derived automatically :-)) b. subtyping makes program analysis easier if you pick a subset of ocaml to mixin with your own DSL,subtyping makes you only need to analyze part of the language with much more type safety. c. overloaded quosi-quotation We provides two Asts for quasi-quotation, one with the location, the other without location(for code generation), they works well together. And the user can also enrich the intermediate Ast with a new constructor while re-use the existing quotation kit. d. minimum dependency Since the namespace of variants is global, we provide a mechanism to store the ast in a normal ocaml value, this adds reflection layer to ocaml automatically while without introducing any dependency. Besides, unlike camlp4, the global namespace also makes the semantics correct Second, we provides the first class programmable parser/lexer. The grammar is not only dynamically extensible, but you can also program the productions as well. This is much different from yacc or menhir, here grammar is programmable means you can parameterize any production. Third, we provides a uniform deriving mechanism Take a look at the code in src/FanAst.ml {:fans|keep off; derive (Map2 Fold2 OIter MetaExpr MetaPatt Map Fold Print OPrint OEq GenLoc Strip ); |}; {:ocaml|INCLUDE "src/Ast.ml"; |}; This will derive the map2, fold2,oiter objects, and metaexpr metapatt lifting, map, fold, pretty printer, strip location for FanAst, the deriving can be customized in tens of lines code. There are a number of enhancements I don't mention here, it would be very helpful that you could suggest what kind of functionality you want, Fan is already much better than camlp4 in all rounds, it is still at alpha stage, so your opinions matter a lot :-) -- Regards -- Bob