hosted/dynamic at-runtime F#?

241 views
Skip to first unread message

Steven Taylor

unread,
Nov 11, 2012, 6:03:26 AM11/11/12
to fsharp-o...@googlegroups.com
Hey,

back-of-the-envelope idea / sketch here.  I'm new to this community, so my apologies if this has been discussed already.

After being delighted by the F# Interactive console I started playing around with FSharp.Compiler.CodeDom.  I was in for a shock. Compilation took a good 2 seconds fpr printfn "Hello World!".  Is this typical?

Open source F# seems to have a weakness, and I wonder if we should think about this more seriously.  Without paying attention to this F# will remain bound to static situations -- and it is such a dynamic expressive language, this would be a pity.  

I wonder if we should take the leadership shown by this python project as something to aim towards and perhaps emulate?


For the pure kernel of the F# ideal, I'm inclined to think that the CLI should be a target, not a home.  Perhaps LLVM as mentioned in a functional londoners video (I forget which). 

best,
-Steven Taylor

P.S. I was looking through my bookshelf of abandoned MS technologies (10+ years worth) and just though that for those who are passionate about this language, that perhaps it is worth going the extra distance.



Tomas Petricek

unread,
Nov 11, 2012, 9:00:49 AM11/11/12
to fsharp-o...@googlegroups.com
Hi Steven,
The CodeDom provider for F# is probably not the best way to compile code on
the fly - it is there mainly for compatibility reasons (it is used by
various projects that generate code during compilation like ASP.NET). It
calls the fsc.exe compiler under the cover, so the 2 second compilation is
mainly the load time of the compiler.

At the moment, F# does not have a great API for calling it interactively
(like IronPython had), but it is definitely something that the community
could do - and I'm sure this would be really appreciated by many.

The best way to approach the problem would be to use API available in
FSharp.Compiler.dll provided by the SimpleSourceCodeServices type:
https://github.com/fsharp/fsharp/blob/master/src/fsharp/vs/SimpleServices.fs

This allows you to compile code into a dynamic assembly (and then run it),
but it only
--
--
You received this message because you are subscribed to the Google Groups
"FSharp Open Source Community" group.
To post to this group, send email to fsharp-o...@googlegroups.com
To unsubscribe from this group, send email to
fsharp-opensou...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/fsharp-opensource?hl=en




Tomas Petricek

unread,
Nov 11, 2012, 9:03:00 AM11/11/12
to fsharp-o...@googlegroups.com
Hi Steven,
The CodeDom provider for F# is probably not the best way to compile code on
the fly - it is there mainly for compatibility reasons (it is used by
various projects that generate code during compilation like ASP.NET). It
calls the fsc.exe compiler under the cover, so the 2 second compilation is
mainly the load time of the compiler.

At the moment, F# does not have a great API for calling it interactively
(like IronPython had), but it is definitely something that the community
could do - and I'm sure this would be really appreciated by many.

The best way to approach the problem would be to use API available in
FSharp.Compiler.dll provided by the SimpleSourceCodeServices type:
https://github.com/fsharp/fsharp/blob/master/src/fsharp/vs/SimpleServices.fs

This allows you to compile code into a dynamic assembly (and then run it)
using esentially the same mechanism as the one used by F# Interactive. So,
once the library loads all the necessary DLLs, it should be pretty fast.

Tomas


-----Original Message-----
From: fsharp-o...@googlegroups.com
[mailto:fsharp-o...@googlegroups.com] On Behalf Of Steven Taylor
Sent: Sunday, November 11, 2012 11:03 AM
To: fsharp-o...@googlegroups.com
Subject: hosted/dynamic at-runtime F#?

Steven Taylor

unread,
Nov 12, 2012, 7:31:57 AM11/12/12
to fsharp-o...@googlegroups.com
The best way to approach the problem would be to use API available in
FSharp.Compiler.dll provided by the SimpleSourceCodeServices type:
https://github.com/fsharp/fsharp/blob/master/src/fsharp/vs/SimpleServices.fs

This allows you to compile code into a dynamic assembly (and then run it)
using esentially the same mechanism as the one used by F# Interactive. So,
once the library loads all the necessary DLLs, it should be pretty fast.

> thanks.  I'll take a look at this.  Maybe it'll be fast enough.

panesofglass

unread,
Nov 13, 2012, 8:33:49 AM11/13/12
to fsharp-o...@googlegroups.com
Thanks for sharing that, Tomas. I have never seen that type.

Do you happen to know why the F# compiler is a CLI-only tool? Why not build the compiler as a library and expose it through a CLI, CodeDomProvider, or even allow consumption in applications? This is probably a better question for Don. I'm sure there are excellent reasons; I just don't know them. I liked Fahad's fork that pulled the library out for general consumption. I would have thought that could easily be plugged back into the CLI.

In other news, I'm working on a Web API that provides FSI as a service. This would be similar to tryfs.net more than the hosted, Silverlight-based tryfsharp.org.

Cheers,
Ryan

Tim Robinson

unread,
Nov 13, 2012, 8:43:27 AM11/13/12
to fsharp-o...@googlegroups.com
Hi Ryan, what have you got so far - do you want to work together?

As it happens, I've been looking though the code for the version 3 compiler this week, with a view to putting together a more natural backend than a hosted copy of fsi.exe. At first I'd like to speed up tryfs.net by pre-loading the FSI code, but thanks to Tomas's explanation below, I can imagine having a REST interface to the compiler.

What I have in mind is something like an F# version of IPython, i.e. a web-based notebook that lets you collaborate on F# code.


--

Steven Taylor

unread,
Nov 13, 2012, 9:02:40 AM11/13/12
to fsharp-o...@googlegroups.com
I'll throw my hat in the ring if you need some help on this.  

-Steven

Tim Robinson

unread,
Nov 16, 2012, 5:58:37 PM11/16/12
to fsharp-o...@googlegroups.com
Hi Tomas, is there an FSharp.Compiler binary that exposes the SimpleServices types? They're public in the source code at Github, but everything in my VS2012 copy of FSharp.Compiler.dll is internal (to the extent that FSharp.Compiler exports nothing publicly).

Thanks,
Tim

Tim Robinson

unread,
Nov 17, 2012, 8:29:22 AM11/17/12
to fsharp-o...@googlegroups.com
Ah, I understand now - this post from Don explains it: https://groups.google.com/d/msg/fsharp-opensource/jAsUqh9Ft4M/4rOYrKgCPlUJ

It's only in the Silverlight build at present.

Ben Winkel

unread,
Nov 17, 2012, 5:50:51 PM11/17/12
to fsharp-o...@googlegroups.com


This api is also in the .NET 4.x FSharp.Compiler.dll you get from the open source release.

It uses a different strong name to the one from Microsoft, so you can use it as copy local (e.g. as part of a hosting plugin for Excel, a game or some other app)

If you want to use it then compiler the open source release on mac/linux - there is a problem compiling on windows right now, see https://github.com/fsharp/fsharp/issues/61
Message has been deleted

Dave

unread,
Feb 19, 2013, 3:39:14 PM2/19/13
to fsharp-o...@googlegroups.com
Tomas,

Are there any examples out there on how to make use of this API?

Ben Winkel

unread,
Feb 24, 2013, 1:29:27 PM2/24/13
to fsharp-o...@googlegroups.com
 
This API is visible if you compile the FSharp.Compiler.dll from the github repo, e.g. look in
 
     lib\release\4.0\FSharp.Compiler.dll
There is a small script using this API in
 
    tests\hosting\hosted.fsx
 
but the stdout is not correctly captured for the interactive case
 
-- ben

On Tue, Feb 19, 2013 at 8:48 PM, Dave <david...@gmail.com> wrote:
Any particular reason why this module is not visible to anything but silverlight?
To unsubscribe from this group and stop receiving emails from it, send an email to fsharp-opensou...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

panesofglass

unread,
Feb 24, 2013, 3:49:18 PM2/24/13
to fsharp-o...@googlegroups.com
I got tied up in other things and completely missed this reply. I can't find the stuff I had. I was planning to start from the Roslyn-based version from Filip Woj. I hadn't made it that far. I also noticed you posted FsNotebook, so you have probably made more progress. And I would absolutely like to collaborate.

Ryan

panesofglass

unread,
Feb 24, 2013, 10:26:06 PM2/24/13
to fsharp-o...@googlegroups.com
This pull request https://github.com/fsharp/fsharp/pull/15 offered the same outside of Silverlight. However, I think it altered a few other things. It might be a good source for determining how to expose types from FSharp.Compiler.

panesofglass

unread,
Feb 24, 2013, 10:28:23 PM2/24/13
to fsharp-o...@googlegroups.com
So the OSS version has exposed these types outside Silverlight? Excellent! Do you happen to know the commit(s) that did this?

Dave

unread,
Mar 9, 2013, 12:23:38 PM3/9/13
to fsharp-o...@googlegroups.com
How does one get intellisense capabilities like the following:

Reply all
Reply to author
Forward
0 new messages