r/dotnet • • Dec 05 '20

Fable 3.0 released

https://fable.io/blog/Announcing-Nagareyama-4.html
51 Upvotes

21 comments sorted by

12

u/Dr-Collossus Dec 05 '20

What is it? I read the “What is Fable” section of the docs but I still don’t quite get it. Is it analogous to TypeScript, in that you write code in F# and it gets transpiled to JavaScript?

11

u/[deleted] Dec 05 '20

Yes, it's an F# to javascript compiler.

Good Example is react bindings (from Feliz)

module App

open Feliz

[<ReactComponent>]
let counter() =
    let (count, setCount) = React.useState(0)
    Html.div [
        Html.button [
            prop.style [ style.marginRight 5 ]
            prop.onClick (fun _ -> setCount(count + 1))
            prop.text "Increment"
        ]

        Html.button [
            prop.style [ style.marginLeft 5 ]
            prop.onClick (fun _ -> setCount(count - 1))
            prop.text "Decrement"
        ]

        Html.h1 count
    ]

open Browser.Dom

ReactDOM.render(counter(), document.getElementById "root")

3

u/software_account Dec 05 '20

Thank you, what is the use case?

8

u/[deleted] Dec 05 '20

Anything you want, but most commonly front end JS (hence the React Example).

You can share a lot of code between client and server, there's even and RPC library which makes wiring things up fairly painless.

2

u/software_account Dec 05 '20

Thank you, did you create this? It’s impressive

5

u/[deleted] Dec 05 '20

I wish, I just use it.

1

u/ramdulara Dec 05 '20

Is it free? What's their commercial model?

3

u/Alikont Dec 05 '20

It's free and open source.

5

u/Jwosty Dec 05 '20

I am personally using it for the UI part of my cross-platform desktop application (I tried doing it in Xamarin.Forms first but settled on this instead because its more reliable for my purposes). That way, it can still all be written in one language but get the power of Javascript UI toolkits. I'm sure I will be switching to Blazor (and fsbolero) in the future if it proves to work for me.

1

u/software_account Dec 05 '20

Awesome, haven’t looked into Blazor yet. Scared of it and F# atm. (Those operators..)

Doing some intense scaling and fighting with MySQL + EF....

ASAP though! Thanks for the share

8

u/Jwosty Dec 05 '20

F# is only scary-looking because it's alien to those unacquainted to it. It can really grow on you if you take a dive, and it really isn't as over your head as you may think (if you look carefully, C# is slowly turning into F#)! I truly believe it's my secret weapon. :)

Oh man. Good luck with your database wrangling!

4

u/Alikont Dec 05 '20

Web front-end UIs.

It's a nice tool because F# has very strict type system and it eliminates a lot of bugs on design time.

2

u/Dr-Collossus Dec 05 '20

Cool thanks. Nice that you can get the benefits of the JavaScript runtime but have your choice of languages.

1

u/software_account Dec 05 '20

I literally said out loud “what the fuck is it?” my wife: O_o

1

u/jhizzle4rizzle Dec 05 '20

100% here for "rescript but for f#"

1

u/fragglerock Dec 05 '20

Use case is being the 'f' in SAFE... a thinger that lets you make websites in F# if you fancy doing that for some reason.

https://safe-stack.github.io/

https://www.compositional-it.com/news-blog/introducing-the-safe-stack/

1

u/chocolatecitytech Dec 05 '20

For a web dev is there a compelling reason to switch to f# given how easy and powerful c# already is? I haven't touched f# yet and part of my reasoning is that

  1. C# does everything I want.

  2. If I wanted all an all out functional why not go with elixir or some "more" functional language. Besides as someone already said c# is already going the way of f#.

I like playing with different languages but I really want to understand "the why f#" for specifically a web developer. My desktop programming days are behind me so am only thinking about web.

3

u/fragglerock Dec 05 '20

Genuinely no idea...

I was thinking I should learn f# to broaden my horizons and the SAFE thing turned up as a way to produce a thing more than 'hello world'.

People seem to love F# but I find it incomprehensible and off putting so I have not got very far using it.

2

u/Alikont Dec 05 '20 edited Dec 05 '20

F# has a lot of nice small things, but overall C# is catching up.

Things I miss in C# compared to F#:

  1. Union types. It's a nice way to represent mutually exclusive states or messages. C# just don't have the same abstraction. Example.

  2. Terse syntax for function combination. This allows basically build readable DSLs on F# alone. Example JSON parser. FParsec is probably the best use-case for F# in .net world.

  3. F# naturally works with React, because React is functional by design. It makes F# probably the best front-end tool right now. It has nice functional compiler to JS, the payload is small and fast (it's basically the same as typical React app), and strict type system is good. But it's competition between F#, TypeScript, JS and Elm, not between F# and C#.

  4. Computational expressions allow you to build almost a custom language. Look here.

But overall F# suffers from the fact that C# is a very good language. Here is a nice article about it.

1

u/chocolatecitytech Dec 05 '20

Some good points. Yeah, I want to try it but I really wanted a good reason. It's tough because I do js/typescript daily. I can get up and running with a new react/nextjs/angular app in no time with c# on the backend.

If I wanted one language for backend and frontend there's blazor with c# and of course some [insert nodejs framework]

I guess I just don't have enough of a compelling reason to make f# my home.