
Fable: F# to JavaScript compiler - galfarragem
http://fable.io/
======
JasonSage
Why not show a code sample on the homepage? None of Home, Docs, or Samples
have a single code snippet on the entire page, you have to click through.

Crystal and Rust are good examples of language homepages that give you an idea
of what you're getting into up front. Or for a transpiled language,
PureScript.

~~~
keithnz
you can go to the samples... but you will quickly notice a lot of the samples
are canvas orineted things, because Fable gets to be in control to do things
F# like. There's a vue and react example, but the code doesn't show any real
advantage. Very little examples of typical web pages.... just a link to fable-
elmish..... so... you may as well use elm. This is a common problem for F# in
general, it hasn't really carved a slice of a world where it dominates. It's a
nice language, but hard to make it a first choice.

Though one area I think it's quite nice is parsing, I like FParsec

~~~
et1975
Hi, fable-elmish author here. Elm is great if you don't care about investing
into two ecosystems or don't have a backend, or don't have a Native client in
addition to Web, or don't care about what JS ecosystem has to offer.

Fable lets one use F# for both frontend and backend, and being able to share
the code (models in particular, but really anything) while maintaining clear
separation of tiers reduces your code base and dramatically improves quality
w/o the need for elaborate tests.

Fable-elmish lets one use the same frontend code and architecture to write
Native and Web apps. Again, YMMV, but at our company being able to transition
an entire team between completely different types of projects avoids expertise
silos and makes truly cross-functional teams possible.

We have OSSed a lot of our backend tech that helps building event-driven
system in F# as well, in case anyone's interested:
[https://prolucid.github.io](https://prolucid.github.io).

As Tomas said, just like Lisp in Paul Graham's "Beating the Averages" has been
his secret weapon, F# is ours.

------
dep_b
The first thing I worry about reading something like this is how leaky the
abstraction will be. I would love to ditch JavaScript for pretty much anything
else but if I need to think about the JavaScript part anyway because of
certain things that I can or cannot do I prefer to think in JavaScript from
the get go.

~~~
tpetricek
This is a tricky one. If the abstractions were not leaky, you would not be
able to interoperate with JavaScript libraries and you'd have to reimplement
everything that powers the modern JS ecosystem. On the other hand, if the
abstractions were too leaky, you'd lose all benefits of a nice language like
F#.

I think Fable strikes the right balance. There are some leaky aspects of how
it compiles to JS, but this means that you can quite well use it with existing
JS libraries and for things like parsing JSON (you can just cast JSON object
to F# records and it'll work).

So, you need to think about something about the JS part when you want to do
JavaScript-y things, but you still get plenty of nice help from the F#
compiler when writing the logic that the functional-first style makes so much
easier.

In my experience with Fable, this pragmatic approach is what makes it great.

~~~
microcolonel
> _you can just cast JSON object to F# records and it 'll work_

Isn't a "JSON object" just a string?

~~~
TomMarius
He probably wanted to say "plain JS object", which is denoted in JSON. You can
put JSON in a string, but the syntax is called JSON as well.

~~~
tpetricek
Yes, that's what I meant, thanks :-). The idea is that you can just write
`unbox<MyType>(jsonParse("{whatever:42}"))`.

------
zaaack
I have been watching and trying Fable for two months after I wrote a demo in
ReasonML/BuckleScript, because I need a full-stack language for my side
projects and Fable is much complete and stable, and the backend story is also
much better than OCaml or BS bindings for Nodejs.

~~~
zaaack
Here are some real-world examples:

A Server-Client full-stack scaffold: [https://github.com/SAFE-Stack/SAFE-
BookStore](https://github.com/SAFE-Stack/SAFE-BookStore)

A React-Native scaffold: [https://github.com/SAFE-Stack/SAFE-
Nightwatch](https://github.com/SAFE-Stack/SAFE-Nightwatch)

------
Osiris
Can anyone point to a resource for learning F# from scratch?

I have tried a few tutorials but the syntax is so foreign to me that I've
found it hard to grasp.

What would be awesome with a project like Fable would be to have a tutorial
for existing JavaScript devs to learn F#. For example, have JavaScript and F#
code side-by-side.

~~~
TheWiseOne
Try this course from FSharpTV: [https://fsharp.tv/courses/fsharp-programming-
intro/](https://fsharp.tv/courses/fsharp-programming-intro/). They have a lot
of other content too but this is the introductory course that's aimed towards
beginners. It might be helpful.

And try the
[https://fsharpforfunandprofit.com/](https://fsharpforfunandprofit.com/) site
too.

------
dominotw
> export { _ as $2665$ };

Why significance does that have in javascript?

[http://fable.io/repl/](http://fable.io/repl/)

~~~
steego
It's exporting the function with the name unicode name "(heart character
here)"

    
    
       let (heart) x y = x + " loves " + y
    

EDIT: I guess Hacker News doesn't support unicode characters. (Not a bad
thing)

------
genzoman
great! now we just need more than two people that know f#. i keed...kinda ;)

~~~
TensorMetric
That would require Microsoft, the F# team, and the vocal F# community members
to actually want F# to be a proper first-class .NET citizen, which sadly isn't
the case.

[https://np.reddit.com/r/fsharp/comments/6tdrwq/after_so_many...](https://np.reddit.com/r/fsharp/comments/6tdrwq/after_so_many_years_still_no_net_native_nor/)

~~~
edgyswingset
As a sometimes-user of F#, I’m quite happy not caring about a dead-end
technology like UWP and .NET Native, thank you very much. I’m glad everyone
else seems to agree about that, too.

~~~
pjmlp
How things are going, I bet those dead-end technologies have a brighter future
than F#, specially when I see those Microsoft bashing comments.

If it comes to be, lets see how long F# survives without Microsoft support.

~~~
edgyswingset
Microsoft bashing? Where did I do that?

I run a few things on .NET Core today and it’s great. I’ll probably runs some
things in Azure soon enough. I just think UWP has no future because its
primary device type (Windows phone) is dead, and it hasn’t seen any uptake in
the enterprise to replace Winforms and WPF. F# seems just fine to me, and it’s
supported for my app type. Perhaps you need to rethink your choices in
development technologies.

~~~
pjmlp
I am speaking about the tone on F# tweets and on Github coments regarding
Windows, UWP and .NET Native.

I did rethink my choices in technology, F# is not worth my time for production
code anymore.

------
igouy
also FunScript "F# to JavaScript with type providers"

[http://funscript.info/](http://funscript.info/)

~~~
tpetricek
Fable pretty much replaced FunScript - all the activity around F# to
JavaScript translation moved from FunScript to Fable nowadays!

~~~
igouy
What's the licensing?

 _" you only pay for what you get"_

------
forresttrump
Aren't languages described as 'functional' a little too often...

~~~
wtetzner
They frequently are, but F# definitely falls into the functional category,
unless you only consider pure functional languages like Haskell.

