[HN Gopher] Fable is a compiler that brings F# into the JavaScri... ___________________________________________________________________ Fable is a compiler that brings F# into the JavaScript ecosystem Author : philonoist Score : 78 points Date : 2021-10-17 08:38 UTC (2 days ago) (HTM) web link (fable.io) (TXT) w3m dump (fable.io) | Taikonerd wrote: | Is it my imagination, or has there been an upswing of interest in | F# on HN recently? | Zababa wrote: | Maybe a combination of churn from Scala, growing popularity of | .NET in general with .NET Core, lack of high-level stuff in Go, | static typing coming to dynamic languages (especially JS), | functional features getting everywhere. Lots of stuff is | pointing at it in a way. | drekipus wrote: | Tooling and marketing budget improvements I'd imagine | sbelskie wrote: | Tooling for sure. I would be shocked in the marketing budget | increased just based on how many recent .NET changes recently | exclude F# (e.g. source generators). | pininja wrote: | There was a wave of popularity in 2017 as well. I used to work | on it full time back then, and enjoyed it a lot. The | SQLProvider [0] and other type providers like it are super | impressive! | | [0] https://fsprojects.github.io/SQLProvider/ | zamalek wrote: | I have yet to learn it myself, but I get the idea that there is | a huge amount of people who "shut up and get shit done" with | it. Posts on HN tend to bring these people to the surface. | | The interest has always been consistent, it's just not vocal. | 2mol wrote: | Yeah, I blame it on version 5 (and dotnet) and the overall | tooling improvements. It has really become an excellent and | easy to pick up language, with not too many warts and a very | good ecosystem. | zz865 wrote: | I hate myself, 5 years ago I gave up dotnet to move to Java | because it was more popular now I'm drowning in Spring beans | and wish I never switched. | svachalek wrote: | Ha, I'd be very interested in seeing a sociology study on | Java. There's nothing about the language itself says you | need to seize on half a dozen design patterns and beat them | into the ground, but that's what every Java project I've | ever seen looks like. | mdm12 wrote: | And version 6 is about to drop! | https://devblogs.microsoft.com/dotnet/whats-new-in-fsharp-6/ | agumonkey wrote: | it's always been bubbling over here | UglyToad wrote: | Partly the question which caused me to brush off my trends site | [0] and add support for'#' and '+' tokens in the search. | | Looks like somewhat of an increase but a very spiky baseline. | | https://hn-trends.eliot-jones.com/Home/Trend?id=f%23&allword... | sbelskie wrote: | I've only played around with it on a few smaller projects, but it | blew me away with the simplicity and expressiveness. I've used it | a few times to make simple web based UIs for personal tooling and | am looking forward to using it on something bigger. | | Just one of the many reasons I find myself more and more excited | by F#. | agumonkey wrote: | maybe rust contender on the frontend | satvikpendem wrote: | Is it named Fable due to its relation to the Fable series which | Microsoft publishes? | kirse wrote: | Along with Fable highly recommend a look at Feliz. A joy to work | with and its ViewEngine can also separately be used w/ Giraffe | just for the syntax: | | https://zaid-ajaj.github.io/Feliz/ | | https://github.com/Zaid-Ajaj/Feliz | sbelskie wrote: | For those interested in Svetle, Sutil is another thing to check | out. Top of my head I can't remember if it is based on or just | inspired by Feliz. | | https://github.com/davedawkins/Sutil | lf-non wrote: | Zaid Ajaj probably has had the biggest impact in establishing | the Fable/F# ecosystem. | | Besides his numerous repos, the Elmish book [1] is really | awesome. | | [1] https://zaid-ajaj.github.io/the-elmish-book/#/ | eatonphil wrote: | > optimized for happiness | | I like React and I like F#. But I never understand this kind of | marketing. It's not that I want things optimized for pain. But | I guess I'm just most interested in the technical choices and | actual performance in the domain over my own happiness? | spankalee wrote: | I don't know a ton about Fable, but they recently wrapped | Google's Lit to allow building functional templating and web | components in it: https://fable.io/Fable.Lit/ | | Seems like a neat project. | phillipcarter wrote: | Fable is a brilliant project. | | It doesn't try to hide the fact that when you write a Fable | program, you're fundamentally in the JS ecosystem. This can be a | bit of a shift if you're used to doing stuff in .NET, but it | means that everything will more or less work with your code. | | It also comes with a few tools/utilities to ease the F#-JS bridge | you're on. | amelius wrote: | > it means that everything will more or less work with your | code | | So you can call any .NET library? | icey wrote: | Since we're in here talking about all kinds of F# goodies, has | anyone spent time with https://wiz.run/? | brundolf wrote: | Maybe I'm biased, but I'm often skeptical of the benefits of | projects like this that translate a language which normally | targets runtime A, into another language that targets a wildly | different runtime B (usually JS or WASM) | | (Disclaimer that I'm not talking about compiling runtime-less | languages for different platforms) | | It just seems like it's going to be a very leaky abstraction, | like there will be tons of corner cases where some behavior isn't | exactly the same and other behavior isn't quite possible, which | will cause libraries and in-house code alike to break in weird | ways. I know that ClojureScript, for example, has several caveats | relative to Clojure; and most of these translators are not nearly | as mainstream (and so don't get nearly as much maintenance | attention) as ClojureScript does. And then there's the messy | question of interacting with the host system, dropping down into | the host language for certain things, etc. | | I haven't really worked with these kinds of systems so I may be | way off, but from the outside it seems like a huge increase in | complexity just so you get to stay in a familiar language | JaggerJo wrote: | I've written quite a lot of F# code for the web over the last | few years. Most of the time things just work as long as you | don't use overly specific .NET BCL stuff. | | We had issues with Dates. Implementing a custom 'ZonedDateTime' | type with native implementations for both target platforms (JS | and .NET) was straight forward. | | Other than that there are a few gotchas when doing 'advanced' | stuff: | | - Fable does not support 'Array2D', 'Array3D', ... - Fable | allows the use of ints but you have to know that at runtime | they all are floats. - Fable does not support FSharp | Quotations. - Fable does not support the full reflection API. | | More here: https://fable.io/docs/dotnet/compatibility.html | | Would definitely recommend F# for both backend and frontend. | It's been a joy. | dwohnitmok wrote: | ClojureScript is in a weird boat because of a constant | background tension in goals of the Clojure community, where on | the one hand Clojure proclaims that it is a "hosted language" | and as such there shouldn't be an expectation of consistent | semantics across different hosts, but on the other hand devs | _really like_ consistent semantics if the language doesn 't | change. So the Clojure community has kind of settled on cljc | files as an indication of "works on all hosts in the way you | would expect" even though that's not any part of the guarantee | that a cljc file provides in any documentation anywhere (it | gives you reader conditionals and that's it). Basically | ClojureScript isn't really sure whether those "caveats" are | bugs or features and neither is the Clojure community at large. | | More broadly they aren't sure whether causing "libraries and | in-house code alike to break in weird ways" on different hosts | is a bad thing (some folks would probably take issue with the | word "break"). | | On the whole however these projects can go very well. I've seen | e.g. ScalaJS and Scala backend projects work very well. They're | a lot less leaky than you would think. The vast majority of | code just works. In particular, there are clean lines between | what is supported by the abstraction and what isn't, and the | latter doesn't affect the former, so in that sense the | abstraction is pretty tight and not leaky. And the major win | isn't so much the familiar language part as it is the ability | to share code and definitions. It's really powerful to change a | line somewhere deep in your backend and have all the places you | need to make a change all the way out to the frontend UI | automatically laid out for you. | | That said the big misconception, and where the abstraction is | incomplete if not leaky, is that these languages allow you to | disregard the runtimes of secondary targets. No compile-to-JS | language I know of has successfully done away with the need to | understand the HTML/CSS/Javascript stack. And that indeed is | extra complexity that should give pause to developers. | | But RE "cause libraries and in-house code alike to break in | weird ways" generally does not seem to be the case for these | compile-to-JS languages. | kevinmgranger wrote: | I'm only passingly familiar myself, so I might be off here-- | but F# already has that sort of feel and experience, where it | has some of its own ways of doing things despite integrating | into the .NET runtime. | | In other words, the language designers and users are already | used to understanding corner cases and integrations into | ecosystems that are different. | brundolf wrote: | Interesting point! I haven't used F# so I assumed it was | pretty "native" to the .NET runtime | | Still- I have to wonder about things like concurrency, which | is perhaps the most obvious limitation of targeting the JS | runtime | kevinmgranger wrote: | There are some caveats they outline for the usual async | stuff[1], but at a cursory glance, it's not that bad. | Thanks to F#'s computation expressions, .NET async code and | Fable.Promise code look almost identical.[2] | | 1: https://fable.io/docs/dotnet/compatibility.html#Caveats- | II | | 2: https://stackoverflow.com/a/54451205/4099287 | phillipcarter wrote: | F# is certainly a .NET language depending on the lens with | which you view it. The object system and lots of its | semantics are the way they are because that's how .NET | works. However, a surprisingly large amount of this stuff | is translatable and makes sense with a JS runtime instead. | The fable authors have managed to thread the needle just | right so that it more or less "feels right". | kervantas wrote: | People would rather write a compiler than write js. Ridiculous. | Smaug123 wrote: | Er, yes? Compilers are _brilliant_ fun. | akdor1154 wrote: | What's even more exciting is there is work underway to allow | Fable to target Python instead: https://github.com/fable- | compiler/Fable/issues/2339 | | These things are bizarre when you think about the tech stack they | lead to, but undeniably still really useful in our unfortunate | real world. I think of F# as 'the pragmatist's functional | programming language', and projects like this follow that | mindset. ___________________________________________________________________ (page generated 2021-10-19 23:00 UTC)