F#. Oh you know you want to

I know this is going to get eyeballs rolling given everything else going on.

But using grasshopper is very much like functional programming isn’t it. I don’t know if any of you have used F# but, well it’s pretty damned good and it’s a more natural segue into coding proper from grasshopper given the functional programming bent.

I just thought, well there are already scripting editors for C# and ironpython in gh, it surely can’t be a biggie adding another for F#, could it? I mean it’s dot net after all. Hey, add VB whilst you’re in there too! :grin:

Just an idea. Don’t shoot me.

I bet David Rutten will be cursing me for suggesting this :smirk:

2 Likes

Dunno about scripting editors - but there is nothing that should hold you back from using F#.

Here an old minimal example of a F# plug-in that provides one component:

And here the original GhShaderNodes plug-in for Grasshopper:

Since then rewritten in C#, but I like the F# code more for this plug-in. Very clean and terse.

add VB whilst you’re in there too!

There is a VB component / editor already. Right next to the C# and python ones.

Some users have been using their own F# editor, but I don’t think it was made publicly available (could be wrong about that).

I have no problems at all supporting more languages, however very few people at McNeel know F# so day-to-day tech support would be a stretch.

Of course there is, my mistake

I hadn’t thought about support impact, it’s good point.
I’m just trying to turn designers into coders and thought F# might be a better way for them. Designers don’t seen to like brackets and colons and I’m trying to keep them away from weakly typed Python as I don’t want to spend my days debugging runtime errors in their code.

It was just a thought.

1 Like

If the new code editor for Rhino7/GH2 supports F# syntax then I think it makes a lot of sense to just add it, it’s better to have something with no official support than not have it at all.

4 Likes

Oh I didn’t know it was in v7, I’m still on 6.

There is an F# editor for Rhino, you could ask @Goswin

Rhino WIP on Windows is v7 to be.

Yeah I know WIP is the next iteration in beta, just haven’t downloaded it yet. Will chase Goswin on this, cheers!

Btw, before I get flamed, I meant dynamically typed python not weakly typed python.

Hi Cottonbale,
Yes i have a proof of concept for an FSharp scripting editor in Rhino.
Let me know if you want to test it or even contribut. It uses avalonedit. So it only works on windows.
Here a preview

1 Like

Autocomplete, type info, and error highlighting is working too for most cases.

1 Like

It can probably be embedded in a GH component too

1 Like

Awesome stuff!

I’ll have a go today, thanks Goswin!!

Thanks for this Nathan!

here is an F# template for a Rhino plugin https://github.com/goswinr/Rhino.FSharpPluginEmptyTemplate

1 Like

So, how do you get FSharp scripting to work in Rhino?

my work in progress F# editor can be tested from here:
https://1drv.ms/u/s!Atin9rLFR_7RlaVI3CH_4qc_Fi7aNw?e=UskanF
there is also a port of rhinoscriptsyntax to F#.
Documentation is still missing.
let me know if you have bugs. Note that fsi runs async. So for UI interaction you need to switch to UI thread:

async{
    do! Async.SwitchToContext Rhino.Scripting.Synchronisation.syncContext
    // you UI code goes here 
    } |> Async.RunSynchronously

or use any of the Rhino.Scripting.Rhinoscriptsyntax function that does this automatically. like rs.GetObject("msg")

1 Like