I suggest we ...

Language Integrate transpilers

Create a framework similar to computation expressions, but built using Roslyn or whatever compiler-like framework would be necessary so that subexpressions would be well-formed and type-safe.

XML Example:
let x1 = xml {%
<?xml version 1.0"?>
<PurchaseOrder OrderDate="1999-10-20">
<Items>
....
</Items>
</PurchaseOrder> %}

let v2 = x1.Root.Attribute("OrderDate").Value

SQL:
let x = sql {%
INSERT INTO TestTable([ID], [Name]) VALUES (@ID, @Name) %}
x.Parameters.AddWith("@ID", 3)
x.Parameters.AddWith("@Name", "My Name")

Or LaTeX, or C#, or CIL, or any other parser that one could imagine.

7 votes
Vote
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    I agree to the terms of service
    Signed in as (Sign out)
    You have left! (?) (thinking…)
    Nick Cooper shared this idea  ·   ·  Admin →

    Many thanks for this suggestion. It is being marked as declined – for discussion see the comments above.

    The idea of allowing language embeddings is certainly not a bad one but given the success of things like embedded SQL processing in the SqlClient type provider it feels that any feature in this area would have to be based around evolving and extending the type provider mechanism. Perhaps a synthesis of ideas is what’s needed here.

    Don Syme, F# Language and Core Library Evolution.

    5 comments

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      I agree to the terms of service
      Signed in as (Sign out)
      Submitting...
      • Don Syme commented  · 

        This seems out of scope for F# given the existing features - instead we would extend the type provider mechanism to continue to allow processing of external languages to be offloaded to external compiler plugin components.

      • Anonymous commented  · 

        I'll add an additional example:

        let cs = CSharp {%
        public class Person
        {
        public string Name { get; set; }
        }
        %}

        As far as the XML version goes, VB supports this currently

      • Anonymous commented  · 

        Type providers do not invoke the compiler to work with the text. I'm talking about syntactic help (from an addition compiler) while inside the {% Escape Sequence %} that has Intellisense and such.

      F# Language

      Feedback and Knowledge Base