caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: bob zhang <bobzhang1988@gmail.com>
To: Caml List <caml-list@inria.fr>
Subject: [Caml-list] Fan, a promising replacement of camlp4
Date: Mon, 21 Jan 2013 00:29:55 -0500	[thread overview]
Message-ID: <CANcqPu4zdAOuVP8j6dNLwn-BLygUtfZ+iTsy+wwyrrR7ogtkBg@mail.gmail.com> (raw)

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

             reply	other threads:[~2013-01-21  5:29 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-01-21  5:29 bob zhang [this message]
2013-01-21 10:43 ` Ivan Gotovchits
2013-01-21 14:19   ` bob zhang
2013-01-22 13:55 ` Török Edwin
2013-01-23  5:25   ` [Caml-list] " Hongbo Zhang
2013-01-23  8:41     ` Török Edwin
2013-01-23 14:59       ` bob zhang

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=CANcqPu4zdAOuVP8j6dNLwn-BLygUtfZ+iTsy+wwyrrR7ogtkBg@mail.gmail.com \
    --to=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;
as well as URLs for NNTP newsgroup(s).