I suggest you ...

Language integrated compiler extensibility

Similar to Boo or Nemerle's syntactic macros, I'd like to be able to tranform and emit F# code during compilation to create new language constructs.

242 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Dan Finch shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

4 comments

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...
  • Johann Deneux commented  ·   ·  Flag as inappropriate

    Regarding computation expressions: Part of the magic actually happens at compile time. More precisely, the compiler turns computation expressions into CPS-style, injecting calls to the custom builder.
    If you mark the methods of your builder as inline, you can even avoid some of the run-time overhead (I saw a page on a russian blog that did this for array and list comprehensions, which showed interesting performance gains).

  • Dan Finch commented  ·   ·  Flag as inappropriate

    Johann: I can't create a function with a type provider. Feeding a quotation to a type provider sounds like a cool way to do this, but as you pointed out, is currently not possible. It also wouldn't address adding new "keywords" or control structures. Computation expressions are very close, but the magic happens at run time, whereas I want magic at compile time (beyond types and properties, and even functions). Syntactic macros in Boo make it delightful to extend Boo from within Boo, and I can only imagine how much better it would be in F# (and more accessible than hacking on the compiler - imagine getting Joinads as a class library rather than a compiler fork).

    That said, it seems to be a driving feature of the compilers I mentioned, and may be a large undertaking, so I would definitely settle for quotations+type providers or something along those lines.

    Some examples of similar features:

    Boo:
    http://jira.codehaus.org/browse/BOO-1121 (using the "macro" macro)
    http://boo.codehaus.org/Syntactic+Macros (outdated)

    Nemerle (good list of common applications):
    http://nemerle.org/wiki/index.php?title=MacroUse

    Template Haskell:
    http://www.haskell.org/haskellwiki/Template_Haskell

    Camlp4 (OCaml):
    http://en.wikipedia.org/wiki/Camlp4#Example

  • Johann Deneux commented  ·   ·  Flag as inappropriate

    Type providers kind of provide that, don't they? What's missing is the ability to feed a quotation or arbitrary data, instead of a string.

Feedback and Knowledge Base