
WebSharper: Make web apps in F# - gagege
http://websharper.com/
======
macca321
It's well intentioned, but this project is destined to go nowhere fast.

Abstracting away web development and http has been tried again and again, and
always ends up being more hassle than plain ol' HTML+JS+HTTP.

Then you've limited yourself to interop with the js libraries they've provided
leaky wrappers over, or you can write your own leaky wrapper if you want to
use coolnewthing.js you saw on github.

And to cap it all, this framework requires commercial licensing for closed
source projects!

~~~
MichaelGG
It's been around for a few years. I was able to use it to quickly whip up some
sorta-complicated UIs for some internal tools. I despise JS, and have spent
hours of time fixing simple casing errors or other things that static typing
would fix. Plus F# the language is quite superior to JS, so I don't feel icky
while working on it.

The other benefit is that I can use all the same type definitions, so I don't
need to write some generator or wrapper around my XHR functions - it just
works.

It's quite easy to just drop out into pure JS if you feel the need. And
defining wrappers is actually very very simple. For example:

    
    
      [<Direct "foo($a, $b)">]
      let foo (a: string) (b: int) = ()
    

Doesn't Google use a Java-based system to do essentially the same thing (GWT)?

But you're right that if you are already happy with JS then there's a lot less
reason to pick it up.

~~~
g8gggu89
GWT has long-ish compile times and it involves quite a house of cards, with
getting the Eclipse plugin to talk to the browser plugin, for the 1? browser
that actually has a plugin. Yeesh :(

~~~
RyanZAG
Fixed in GWT 2.7 builds (already available):

[https://www.youtube.com/watch?v=qpCSbj36O44&feature=youtu.be](https://www.youtube.com/watch?v=qpCSbj36O44&feature=youtu.be)

------
gagege
This looks super interesting. I don't think I've ever seen anything like it.

At first I thought it was similar to Classic ASP or JSPs, but after looking at
some the examples, it's more like a JS framework in that it generates HTML
dynamically with client side code. But, the thing that really looks cool to me
is the interop between client and server that you can do.

You can use the exact same "type Person = {Name:string; DOB:DateTime;}" on the
server and client. That's about as DRY as you can get, I think.

~~~
MichaelGG
It's a F#-to-JS compiler, a UI framework, and an RPC system all built into
one. Script# is similar, for C#, but I don't think it got that far? MS did
start "Project Volta" IIRC but then gave up on it. There's also FunScript:
[http://funscript.info/](http://funscript.info/) but that seems more focused
only on the JS generation part.

I don't know why Micrsoft doesn't buy these guys and deliver this as a core
solution. I'd guess it's because it's not on C#, and MS marketing doesn't know
what to do with F#. They want to pigeonhole it as "F# is a special language
for like, scientists and stuff. Don't worry, it ain't got nothing on C#." And
hey, with enough time and resources, C# may catch up on some of the things.
With Rosyln, I think it'd be easier to make a C# WebSharper thing.

~~~
kevingadd
There are already a few approaches out there for compiling C# to JS, like my
JSIL ([http://jsil.org/](http://jsil.org/)) and Script#'s unofficial
successor, Saltarelle ([http://www.saltarelle-
compiler.com/](http://www.saltarelle-compiler.com/)). I believe there is a new
Roslyn-based C#->JS compiler in the works as well.

I'm not aware of anything that approaches WebSharper's level of integration,
though. It's a really impressive piece of work.

~~~
MichaelGG
Any idea why Microsoft isn't doing this as a first-class thing, instead of
creating half-fixes like TypeScript?

------
n72
Is this an arms length Jetbrains thing? If not, it seems awfully odd that its
name is so close to Resharper and the parent company is called IntelliFactory,
which is so close to IntelliJ. I guess there's nothing wrong with that. Just
odd.

~~~
lstamour
Ignoring, of course, that (a) they've probably used or heard of ReSharper and
(b), both F# and C# pronounce the hash as "sharp"? ;-) I suppose it could be
confusing but it wasn't the first thing I thought of...

------
MichaelGG
WebSharper is really fantastic. F#'s a great language, and not having to leave
it and deal with JavaScript is a great boon. So many problems simply disappear
due to type checking.

~~~
superfunc
I wanna knit that last sentence on a sweater for myself. Okay, maybe not, but
I really liked it.

------
Rapzid
This looks very interesting in the same way as Clojurescript but with F# and
potentially a smoother experience.

Has anyone used this that can provide some insight into it? Does it work with
entity framework? OWIN? What's the story with the F# to javascript
compilation; did they invent that or is it another project? Who are these
people?

I think it's a shame that the C#/.NET ecosystem can't seem to have FOSS nice
things because it really hampers stuff gaining traction. However I find the
open source license for this is very clear and generous; I still can't seem to
figure out if ServiceStack is safe to use :| This should allow for learning
the framework and providing nice things to the community, and then the
licensing seems reasonable compared to the value proposition for working on
commercial software.

~~~
DennisP
Perhaps worth mentioning, I recently saw a presenter say his company is moving
away from Entity Framework in favor of F# type providers.

Agree on FOSS. It's nice this company will license to me for opensource
projects, but what happens if they go out of business?

~~~
Rapzid
I'm not sure TBH, but most of their stuff is appears to be on github as well.

------
davidgrenier
I've been using WebSharper in production for 20 months now and I wouldn't
consider doing web development any other way.

People have mentionned that such abstraction generally become more trouble
then they are worth but I completely disagree.

In particular the question would be what are the corner cases that will make
the abstraction more difficult to use and ruin your overall productivity and I
haven't found anything so far.

What I find difficult though isn't creating wrappers around existing external
javascript libraries but rather learning the quirks of each of them. For
instance, I happen to maintain a WebSharper wrapper around the Kendo Web
library (see here
[https://github.com/davidgrenier/Kendo](https://github.com/davidgrenier/Kendo))
with the goal of abstracting away the complexity from my code base and where I
spend most of my time is trying to figure out how to properly use any new
control we've yet to use in production. This process is tedious and error
prone because the examples on the Kendo website aren't exhaustive, the
documentation isn't specific about the semantics of the library and just the
brittle nature of javascript development. I spend lots of time in the chrome
debugger and their online tool figuring out how things work. The productivity
gain from isolating that from my code base is significant.

F# as a language is quite understated, more companies are using it than it
seems (many of which in stealth mode) and so is the case for WebSharper.
IntelliFactory has been selling licences to many of their closed-source
clients, my employer being an example but also I'm aware that MSR uses it
internally on a few projects and was told the developpers there love it. The
fact that my employer continues to pay the licence, gives me work on the
project and has recently hired another developer working full time with
WebSharper indicates that they consider the value to be at least on par with
everything else we do.

Over the 3+ years I've been using WebSharper, I've had to report only a single
bug Monday of last week (see here
[https://bitbucket.org/IntelliFactory/websharper/issue/288/sy...](https://bitbucket.org/IntelliFactory/websharper/issue/288/systemdatetimenow-
on-ie8)) in the WebSharper core libraries related with compatibility issue in
old version of IE and the bug was fixed within the week and had access to an
updated WebSharper package from nuget.

WebSharper isn't just an F# to JavaScript compiler, they also offer powerful,
paper-worthy abstractions to improve developer productivity:

-Transparent RPC calls from client to server (combined with static typing this is one of my preferred feature).

-Combinators for composing pages and managing routes in an elegant typesafe way.

-The ability to create standard server-side markup and yet SPA page building is even better as you get to pick what you carry over the wire and simply create all your markup on the client.

-Tools to create extensions around external javascript libraries (I've personally used WIG and works really well and I learned a few things about design while using it to boot).

-If you have access to Libraries that offer TypeScript bindings (like Kendo does) IntelliFactory can generate the wrappers for you.

-Tons of precreated wrapper for you to simply use

-Combinators to compose data/UI controls/event flow handling like Formlets/Piglets and now UI.Next which is excellent, I've come to appreciate all three and we're using Piglets in production though UI.Next should go a long way to allow you to do anything you need.

-Use existing abstractions in the standard F# development experience which would be hard to get otherwise (async workflows is an example).

I don't have strong opinions one way or another on licencing but as been
mentionned before IntelliFactory generates revenues and as such I'd be
skeptical of someone claiming that such and such model "doesn't work". Besides
most of the concerns I've seen here seems philosophical rather than about
direct impediments the licencing creates on what they had to do. Indeed the
licencing cost my employer has to be is insignificant compared to the benefits
and I personally do not pay for a licence on my own stuff.

Microsoft's position around the .NET ecosystem is sound, they provide the CLR,
Base Library and a world class development environment. The rest is open to
the community to drive the libraries/toolset they need, after all Microsoft
can't do everything and it seems to me would tie in the community to
Microsoft. You can see the latest open sourcing of the Roslyn compiler as a
reflection of that. Likewise, the F# compiler service project and the
direction taken by the F# Power Tools and the way Microsoft supports this
initiative to enhance the VS development experience sends the same message.
Speaking with Don Syme he indicated that technically there wouldn't be
anything standing in the way of doing the equivalent of what IntelliFactory
did with the new C# compiler, though you can be sure of two things: Microsoft
won't be doing it and it's likely a tremendous amount of work.

I haven't played with any other similar toolset (ClojureScript/Purescript/GWT
comes to mind) and as such I will not comment on those. But I will advise
against listening to advice from anyone who hasn't used any of those specific
libary. Even better, sit down and spend the time required to make it familiar
and then you'll be a better judge.

If you are already using F#, I urge you to put 10-20 hours on it, you will
thank yourself. If you aren't using F#, in my mind, WebSharper is just another
wonderful reason to start doing so.

~~~
weichi
How leaky is the abstraction? Can you effectively use this with very little
prior knowledge of front-end web development?

And what is the state of F# on Linux these days?

~~~
davidgrenier
As all abstractions are leaky I have to concede that it has to be, but
considering the size of the abstraction it's actually surprising how little
gets in the way of getting things done (short of getting the hand of it for
which the learning curve is far within that of WPF must have been for some
people).

As far as as doing away with Web Development skill I would say no. As opposed
to what ASP.NET used to do WebSharper doesn't try reinvent Web Development so
one can "leverage" their existing Web Development skillset as opposed to have
it superseded with something else.

On the other hand, being that I myself am a pretty bad web developer (despite
of it being my official title), having static typing on a set of library that
maps to HTML can really help (IntelliSense and simply preventing you from
compiling something that wouldn't work). The other abstractions are just on
top of everything else yet uses functions with the names you may be familiar
with to produce markup.

Plus, I find that having functions as opposed to open and closing tags with
the XML syntax is better on the eyes:

    
    
      Div [
        Span [Text "Hello"]
        Input [Type "Submit"]
      ]
    

as opposed to:

    
    
      <div>
        <span>Hello</span>
        <input type="submit"></submit>
      </div>
    

Another aspect is how easy it is to refactor blocks of markup away into
function calls and use all existing F# functions over collections to
programmatically produce content:

    
    
      [
        "David", "Grenier"
        "Anton", "T."
        "Loic, "D."
      ]
      |> List.map (fun (firstName, lastName) ->
         let lbl text = Label [Text text]
         LI [lbl firstName; lbl lastName]
      )
      |> UL
    

If you have a little imagination, you can see this can go a long way.

------
zzen
I might be missing a point, but how is this different from tried-and-failed
GWT?

Apart, obviously, in language of choice.

~~~
ianlevesque
To be fair, F# vs. Java is more than a trivial difference.

~~~
_random_
Yes, the approach is a dead-end but the language is awesome.

------
hderms
Wow this looks awesome. Always wanted to give F# a try, now I have no excuse!

------
iamleppert
Another monolithic framework that will likely catch some unsuspecting CTO or
director and ultimately be his demise, or someone who doesn't want to learn
javascript (such people still exist, sadly).

~~~
nbevans
Nobody really "wants" to learn JS. It's a hateful little language and the
sooner it gets nuked from orbit or at least abstracted away to become merely
the "assembly language of the web", the better.

While I don't agree WebSharper is monolithic - it's anything but that. I do
agree that it is a bear trap. They could go bust at any moment and leave you
with a big headache.

Even as a F# dev I have deliberately avoided using it because yes I agree with
some of the sentiment here that the licensing model is a bit odd, but also the
thought of needing to write a Binding for basically any JS library it doesn't
support out of the box is quite a burden that will never go away. And can
really slow down a new project that wants to iterate fast.

I firmly believe in using the best tools for the job at hand. So that means a
F# back-end and a AngularJS front-end. It's a PITA maintaining two domain
models in each, and similar validation logic etc, but such is life sometimes.
What I lose in the domain model side, I gain back in a rich and vibrant set of
available AngularJS modules and JS libraries.

------
sudowhodoido
That's interesting. I appear to have actually accidentally written a chunk of
this in C# for a product a couple of years back. The approach is pretty much
identical.

------
hamxiaoz
Does anybody know what's the 2 chrome extensions displayed in the screenshot?

~~~
JosephRedfern
The first is "Google Hangouts"
([https://chrome.google.com/webstore/detail/hangouts/nckgahada...](https://chrome.google.com/webstore/detail/hangouts/nckgahadagoaajjgafhacjanaoiihapd?hl=en)),
the second is "Awesome Screenshot"
([https://chrome.google.com/webstore/detail/awesome-
screenshot...](https://chrome.google.com/webstore/detail/awesome-screenshot-
captur/alelhddbbhepgpmgidjdcjakblofbmce?hl=en)).

------
theoutlander
This is everything I wish Script# could've been!

------
shamney
what are the standard tools for working with databases with f# and websharper?

~~~
tarmil
WebSharper is completely agnostic in this regard, so the question boils down
to what is available for F#.

The idiomatic way to deal with databases is using one of the available type
providers. Basically, a TP generates types at compile time, in a way that
actually plays quite nicely with IntelliSense [1]. In the case of db TPs,
they're parameterized by a connection string and connect to the db to extract
the schema and generate the appropriate types. Several exist [2];
SqlDataConnection and SqlEntityConnection are built-in, FSharp.Data.SqlClient
and FSharp.Data.SqlProvider are community contributed. They all use query
expressions (basically, F#'s extensible version of LINQ syntax) except
SqlClient which directly uses SQL in a string (but still checks the query at
compile time and passes arguments cleanly, thanks to the TP) and is therefore
more like a (safer) micro-ORM.

[1]: [http://msdn.microsoft.com/en-
us/library/hh156509.aspx](http://msdn.microsoft.com/en-
us/library/hh156509.aspx) [2]: [http://fsharp.org/guides/data-
access/](http://fsharp.org/guides/data-access/)

------
solomatov
The project is really great, however license is really bad. A modern
framework, should be open source under liberal license. Licenses like this
worked in 90s, but currently they don't work.

~~~
RussianCow
If you don't like the license, don't use the framework. It's that simple.
Charging for commercial licenses for libraries is a perfectly valid business
strategy, and I can see lots of F# developers paying for this.

~~~
imanaccount247
>If you don't like the license, don't use the framework

That was the point, remember? Because of the terrible license, very few people
will use it. So it will stay tiny and/or die out.

>and I can see lots of F# developers paying for this.

That's a non-sequitur. I pay for lots of free software. The problem is not
cost, it is freedom.

~~~
belorn
You have the freedom to do _anything you want_ from the result of using this
framework.

I also have the freedom to do so with what you make, if I am a user of it.

Why are you so dead set on taking away my freedom. Adding restrictions on what
I can do with the work you created from that framework is kind of rude when
the developers is asking you to share, and share alike.

~~~
imanaccount247
>You have the freedom to do anything you want from the result of using this
framework.

No I do not.

>I also have the freedom to do so with what you make

Then clearly I do not have the freedom to do anything I want.

>Why are you so dead set on taking away my freedom

I am taking nothing from you. I release all my code under the ISC license.
That is free. Restrictions are not freedom.

>the developers is asking you to share, and share alike.

The developers can ask whatever they like. And I can decline their offer. I
will continue to use free software instead. Why is it so upsetting that
someone would choose not to use non-free software? If the developers find my
absence to be a problem, they are welcome to change make their software free.
I have no interest in shareware.

~~~
belorn
While I sincerely doubt that you release all your code under the ISC license,
I will take your word on it.

That mean you can use any open source license and release your contributions
under that license. Be that BSD, GPL, MIT, Apache... what ever it is, _your_
contributions can always be under the license of your choice.

So yes, you do have the freedom to do what _you_ claim _you_ only do, ie,
release code you write under ISC license. 100% freedom to do exactly that.
Write a addon to AGPL and release that add-on as ISC? No legal problem at all.

If you want freedom to release code someone else has written under the license
of your choice, then I sit in the same boat. I would like too to have the
freedom to chose that, but alas, copyright wont' allow that. It would be a
neat freedom to chose the license of OS X and windows.

~~~
imanaccount247
So, you have no idea what you are talking about, but you want to tell me both
what I actually do, and what I should do? Gee, that's really compelling.

