ionide / ionide-vscode-fsharp

VS Code plugin for F# development
http://ionide.io
MIT License
849 stars 276 forks source link

Paste as F# feature #1979

Open jkone27 opened 5 months ago

jkone27 commented 5 months ago

websites like:

https://codingfleet.com/code-converter/csharp/fsharp/

integrate with some GPT / LLLM engine to convert code X to F# code, useful e.g. for C# examples (most examples for .net are in C# not F#). This could provide ways to convert code from lang-x to lang-y, probably using LLM/GPT behind the scenes, would be great to have an integration of this kind in ionide

after copying C# code (or javascript or python code) from a project, we could "paste as F# code"

example

// Create a canvas
var canvas = new Canvas(16, 16);

// Draw some shapes
for(var i = 0; i < canvas.Width; i++)
{
    // Cross
    canvas.SetPixel(i, i, Color.White);
    canvas.SetPixel(canvas.Width - i - 1, i, Color.White);

    // Border
    canvas.SetPixel(i, 0, Color.Red);
    canvas.SetPixel(0, i, Color.Green);
    canvas.SetPixel(i, canvas.Height - 1, Color.Blue);
    canvas.SetPixel(canvas.Width - 1, i, Color.Yellow);
}

// Render the canvas
AnsiConsole.Write(canvas);

gets converted to

// added as we paste from C#, most likely needed
#nowarn "20"

// Create a canvas
let canvas = new Canvas(16, 16)

// Draw some shapes
for i in 0 .. canvas.Width - 1 do
    // Cross
    canvas.SetPixel(i, i, Color.White)
    canvas.SetPixel(canvas.Width - i - 1, i, Color.White)

    // Border
    canvas.SetPixel(i, 0, Color.Red)
    canvas.SetPixel(0, i, Color.Green)
    canvas.SetPixel(i, canvas.Height - 1, Color.Blue)
    canvas.SetPixel(canvas.Width - 1, i, Color.Yellow)

// Render the canvas
AnsiConsole.Write(canvas)

which is indeed equivalent