caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Fan, a promising replacement of camlp4
@ 2013-01-21  5:29 bob zhang
  2013-01-21 10:43 ` Ivan Gotovchits
  2013-01-22 13:55 ` Török Edwin
  0 siblings, 2 replies; 7+ messages in thread
From: bob zhang @ 2013-01-21  5:29 UTC (permalink / raw)
  To: Caml List

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Fan, a promising replacement of camlp4
  2013-01-21  5:29 [Caml-list] Fan, a promising replacement of camlp4 bob zhang
@ 2013-01-21 10:43 ` Ivan Gotovchits
  2013-01-21 14:19   ` bob zhang
  2013-01-22 13:55 ` Török Edwin
  1 sibling, 1 reply; 7+ messages in thread
From: Ivan Gotovchits @ 2013-01-21 10:43 UTC (permalink / raw)
  To: bob zhang; +Cc: Caml List

bob zhang <bobzhang1988@gmail.com> writes:

Are there any possibilities that Fan will be backported to ocaml 3.12 or
even 3.11?

-- 
         (__) 
         (oo) 
   /------\/ 
  / |    ||   
 *  /\---/\ 
    ~~   ~~   
...."Have you mooed today?"...

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Fan, a promising replacement of camlp4
  2013-01-21 10:43 ` Ivan Gotovchits
@ 2013-01-21 14:19   ` bob zhang
  0 siblings, 0 replies; 7+ messages in thread
From: bob zhang @ 2013-01-21 14:19 UTC (permalink / raw)
  To: Ivan Gotovchits; +Cc: Caml List

The only thing that is version dependent is
src/Ast2pt.ml, since we use polymorphic variants to encode the Ast,
for 3.12 or 3.11, it only picks a subset of the constructors, it would
not be too hard to backport to 3.12 or other compiler patches

On Mon, Jan 21, 2013 at 5:43 AM, Ivan Gotovchits <ivg@ieee.org> wrote:
> bob zhang <bobzhang1988@gmail.com> writes:
>
> Are there any possibilities that Fan will be backported to ocaml 3.12 or
> even 3.11?
>
> --
>          (__)
>          (oo)
>    /------\/
>   / |    ||
>  *  /\---/\
>     ~~   ~~
> ...."Have you mooed today?"...



-- 
Regards
-- Bob

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [Caml-list] Fan, a promising replacement of camlp4
  2013-01-21  5:29 [Caml-list] Fan, a promising replacement of camlp4 bob zhang
  2013-01-21 10:43 ` Ivan Gotovchits
@ 2013-01-22 13:55 ` Török Edwin
  2013-01-23  5:25   ` [Caml-list] " Hongbo Zhang
  1 sibling, 1 reply; 7+ messages in thread
From: Török Edwin @ 2013-01-22 13:55 UTC (permalink / raw)
  To: caml-list

On 01/21/2013 07:29 AM, bob zhang wrote:
> 
>        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 :-)
> 

How do you build it?
I tried this but it failed:
$ ocaml -version
The OCaml toplevel, version 4.00.1
$ ocamlbuild -clean
$ ocamlbuild cold/FanDriver.native

+ ocamlfind ocamlc -annot -w +a-4-32-30 -c -w -41 -I cold -I cold/Lib -o cold/Lib/Ctyp.cmo cold/Lib/Ctyp.ml
File "cold/Lib/Ctyp.ml", line 92, characters 21-25:
Error: The record field label FSig.ctyp belongs to the type FSig.col
       but is mixed here with labels of type FSig.record_col
Command exited with code 2.
Compilation unsuccessful after building 88 targets (0 cached) in 00:00:08.


Best regards,
--Edwin

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Caml-list] Re: Fan, a promising replacement of camlp4
  2013-01-22 13:55 ` Török Edwin
@ 2013-01-23  5:25   ` Hongbo Zhang
  2013-01-23  8:41     ` Török Edwin
  0 siblings, 1 reply; 7+ messages in thread
From: Hongbo Zhang @ 2013-01-23  5:25 UTC (permalink / raw)
  To: Török Edwin; +Cc: caml-list

On 1/22/13 8:55 AM, Török Edwin wrote:
> On 01/21/2013 07:29 AM, bob zhang wrote:
>>
>>         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 :-)
>>
>
> How do you build it?
> I tried this but it failed:
> $ ocaml -version
> The OCaml toplevel, version 4.00.1
> $ ocamlbuild -clean
> $ ocamlbuild cold/FanDriver.native
>
> + ocamlfind ocamlc -annot -w +a-4-32-30 -c -w -41 -I cold -I cold/Lib -o cold/Lib/Ctyp.cmo cold/Lib/Ctyp.ml
> File "cold/Lib/Ctyp.ml", line 92, characters 21-25:
> Error: The record field label FSig.ctyp belongs to the type FSig.col
>         but is mixed here with labels of type FSig.record_col
> Command exited with code 2.
> Compilation unsuccessful after building 88 targets (0 cached) in 00:00:08.
>
Hi,
    It seems that I used 'record name disambiguation' feature in the 
trunk accidentally(which is trivial to fix).
    Would you have a try using the trunk compiler?
>
> Best regards,
> --Edwin
>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Caml-list] Re: Fan, a promising replacement of camlp4
  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
  0 siblings, 1 reply; 7+ messages in thread
From: Török Edwin @ 2013-01-23  8:41 UTC (permalink / raw)
  To: Hongbo Zhang; +Cc: caml-list

On 01/23/2013 07:25 AM, Hongbo Zhang wrote:
> On 1/22/13 8:55 AM, Török Edwin wrote:
>> On 01/21/2013 07:29 AM, bob zhang wrote:
>>>
>>>         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 :-)
>>>
>>
>> How do you build it?
>> I tried this but it failed:
>> $ ocaml -version
>> The OCaml toplevel, version 4.00.1
>> $ ocamlbuild -clean
>> $ ocamlbuild cold/FanDriver.native
>>
>> + ocamlfind ocamlc -annot -w +a-4-32-30 -c -w -41 -I cold -I cold/Lib -o cold/Lib/Ctyp.cmo cold/Lib/Ctyp.ml
>> File "cold/Lib/Ctyp.ml", line 92, characters 21-25:
>> Error: The record field label FSig.ctyp belongs to the type FSig.col
>>         but is mixed here with labels of type FSig.record_col
>> Command exited with code 2.
>> Compilation unsuccessful after building 88 targets (0 cached) in 00:00:08.
>>
> Hi,
>    It seems that I used 'record name disambiguation' feature in the trunk accidentally(which is trivial to fix).
>    Would you have a try using the trunk compiler?

It works with trunk.

The ./re script needs this tiny patch to get rid of a bashism, and then it works too:

diff --git a/re b/re
index 63562dd..3d1c1c7 100755
--- a/re
+++ b/re
@@ -2,7 +2,7 @@
 # -*- Mode:Shell-script -*-
 set -e
 PROGNAME=$(basename $0)
-function error_exit
+error_exit()
 {

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [Caml-list] Re: Fan, a promising replacement of camlp4
  2013-01-23  8:41     ` Török Edwin
@ 2013-01-23 14:59       ` bob zhang
  0 siblings, 0 replies; 7+ messages in thread
From: bob zhang @ 2013-01-23 14:59 UTC (permalink / raw)
  To: Török Edwin; +Cc: caml-list

Thanks, I have made the changes.
btw, currently some work is being done in aggr branch
An obvious difference is that I used
'{| |}' instead of '<< >>' for quotation and '$' instead of '$$' for
antiquotation.(for c/c++ friendly and {} works nice with editors)

On Wed, Jan 23, 2013 at 3:41 AM, Török Edwin <edwin+ml-ocaml@etorok.net> wrote:
> On 01/23/2013 07:25 AM, Hongbo Zhang wrote:
>> On 1/22/13 8:55 AM, Török Edwin wrote:
>>> On 01/21/2013 07:29 AM, bob zhang wrote:
>>>>
>>>>         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 :-)
>>>>
>>>
>>> How do you build it?
>>> I tried this but it failed:
>>> $ ocaml -version
>>> The OCaml toplevel, version 4.00.1
>>> $ ocamlbuild -clean
>>> $ ocamlbuild cold/FanDriver.native
>>>
>>> + ocamlfind ocamlc -annot -w +a-4-32-30 -c -w -41 -I cold -I cold/Lib -o cold/Lib/Ctyp.cmo cold/Lib/Ctyp.ml
>>> File "cold/Lib/Ctyp.ml", line 92, characters 21-25:
>>> Error: The record field label FSig.ctyp belongs to the type FSig.col
>>>         but is mixed here with labels of type FSig.record_col
>>> Command exited with code 2.
>>> Compilation unsuccessful after building 88 targets (0 cached) in 00:00:08.
>>>
>> Hi,
>>    It seems that I used 'record name disambiguation' feature in the trunk accidentally(which is trivial to fix).
>>    Would you have a try using the trunk compiler?
>
> It works with trunk.
>
> The ./re script needs this tiny patch to get rid of a bashism, and then it works too:
>
> diff --git a/re b/re
> index 63562dd..3d1c1c7 100755
> --- a/re
> +++ b/re
> @@ -2,7 +2,7 @@
>  # -*- Mode:Shell-script -*-
>  set -e
>  PROGNAME=$(basename $0)
> -function error_exit
> +error_exit()
>  {



-- 
Regards
-- Bob

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2013-01-23 15:00 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-21  5:29 [Caml-list] Fan, a promising replacement of camlp4 bob zhang
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

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).