←back to thread

Why F#?

(batsov.com)
438 points bozhidar | 1 comments | | HN request time: 0.207s | source
Show context
raphinou ◴[] No.43547463[source]
F# was for me the best functional language when I looked at rewriting a Ruby on Rails app. I wanted to go with a functional language, as it seems to better fit my thinking and reasoning, and I looked at Haskell, Ocaml, Scala, F#.

Being a stranger to Microsoft technologies, F# was the least likely to be chosen, but easily became the first choice. Haskell's purity made it hard to adopt (for me), Ocaml's ecosystem is subpar (there wasn't even a clear choice for a library to interact with postgresql, I couldn't install the latest version due to its reliance on an obscure tool whose name I forgot and didn't get help on the forum), and Scala is seems complex....

F# was surprisingly easy to get started with. The community is mis-managed by a corporate-minded approach (requiring people to become member of the F# software foundation to get access to the official slack!), but its members are friendly, smart and ready to help. The ecosystem is great with access to all the dotnet libraries (some complain there's a mismatch as most of those are developed for use with C#, but I rarely got in trouble for using them).

There are also great libs and frameworks available. Like https://github.com/SchlenkR/FsHttp to easily interact with http servers, to the point that I find it easier to use than a dedicated library. Or https://github.com/CaptnCodr/Fli , to run commands. And last but not least, https://www.websharper.com/ is the best web framework I have encountered across all ecosystems. Their reactive approach to web ui really allows me to develop complex interfaces in a maintainable way.

This became a longer message than I thought, probably due to my enthousiasm for the language. For complete transparency, the situation is not perfect, and in my experience the tooling is not the best.

If you want more info, I blogged about it a couple of months ago: https://www.asfaload.com/blog/consider-fsharp/

replies(5): >>43547792 #>>43547982 #>>43548045 #>>43548126 #>>43549735 #
mike1o1 ◴[] No.43548045[source]
There was a large group of folks that left Ruby on Rails for Elixir (even has a similar looking syntax), yet it wasn't on your list of languages to consider. Just curious, was there a particular reason?
replies(1): >>43548268 #
raphinou ◴[] No.43548268[source]
I should have mentioned in the message, but I was looking for a strongly typed language. I was an avid-user of dynamically-typed languages, but that particular Ruby on Rails app became unmaintainable, and part of the culprit was due to the dynamic typing. I hoped that using a statically typed language would make it easier to maintain a complex app in the long term. And I must say that it totally materialised, to the point that I don't want to develop in dynamically typed languages anymore.

Here's an example: as I said in my original message, I was a complete stranger to the dotnet ecosystem, and I learned the F# language at the same time. And I decided to develop the app as a library project to be used by the web app. I completely missed the prevalence of the async approach in the dotnet, and all my code was synchronous. One day, about half-way in the project, I realised I needed to switch to async code. Had this happened in a dynamically typed project, it would have been hell for me. Maybe it's me that can't grasp a project well enough, but I need the type-guardrails to find my way in large refactorings. And with the strong types, large refactorings can be done confidently. They don't replace tests, but make the refactoring process much more smooth.

The app is open source and its code is at: https://gitlab.com/myowndb/myowndb It doesn't have a lot of users, not the least due to lack of marketing and polishing the user experience. But I am satisfied of what I learned developing it!

replies(3): >>43548622 #>>43549211 #>>43554327 #
DonaldPShimoda ◴[] No.43549211[source]
This is a really minor point, but "strongly typed" and "statically typed" are not interchangeable terms. In the context of your comments here, you are exclusively interested in the static nature of the type system, rather than anything about the "strength" of it (which is something totally different and inconsistently defined).
replies(2): >>43549320 #>>43554638 #
throwaway2037 ◴[] No.43554638[source]
Can you explain more about strongly typed vs statically typed?
replies(2): >>43554730 #>>43554839 #
baq ◴[] No.43554730[source]
strong typing: 2 + "2" is an error (e.g. Python vs JS)

static typing: 2 + "2" does not compile/parse (e.g. Python vs mypy, Typescript vs JS)

this is a very simplistic example, but should get you to feel the difference.

replies(2): >>43555330 #>>43557742 #
volemo ◴[] No.43557742[source]
> static typing: 2 + "2" does not compile/parse (e.g. Python vs mypy, Typescript vs JS)

I think this example is not correct, because static typing doesn’t affect how values of different types interact. And while I don’t know of any staticly typed language where specifically `2 + “2”` is a valid expression, statically typed languages definitely can be weakly typed: the most prominent example is C where one can combine values of different types without explicitly converting them to the same type (`2 + 2.0`).

I believe strong/weak and static/dynamic are orthogonal. And my examples are:

- Strong: `2 + “2”` is a error,

- Weak: `2 + “2”` makes 4 (or something else, see the language spec),

- Static: `var x = 2; x = “2”` is an error,

- Dynamic: `var x = 2; x = “2”` is fine.

replies(1): >>43559043 #
sparkie ◴[] No.43559043[source]
Dynamic typing can forbid the latter (at runtime), but it's implementation dependent. There's a further distinction, Latent typing, which is where types are associated with values rather than variables.

But a dynamic language can have types associated with variables, and it can forbid changing those types after their types have been checked the first time.

replies(1): >>43560968 #
1. volemo ◴[] No.43560968[source]
> But a dynamic language can have types associated with variables, and it can forbid changing those types after their types have been checked the first time.

So, like C++ with `auto`?