this is also a good article on the topic:
comparing-scala-to-fsharp
as always, best way is to try for yourself!
//dotnet fsi --> starts F# interactive
//or open vscode and a .fsx file, install ionide, and start typing
#r "nuget: FSharp.Data" //will download your package
open FSharp.Data
//and you are good to use it
let add x y =
x + y
let r = add 1 2
type MyJson = JsonProvider<"""{ "test" : "me" }""">
let sample = MyJson.GetSample()
let me = sample.Test // string! typed, and is "me"
The very big difference to understand when checking functional languages is understanding language families and history, and know why ML language was invented and why Milner won an ACM touring award for it.
The Why is the ML type system.
both F# and Scala are statically (strongly) typed languages, but the strongest differences in my view are:
- Scala has no ML type inference, and never will, and has very sad curly braces like C languages used just for scoping.
- F# doesnt have higher order kinds (scala/haskell pp brag a lot a about it) also for a language design choice, the F# lang directive thought wasn't really needed in 99% of cases of real day to day programming and would confuse people (which indeed it does most of times)
- F# uses curly braces for CE (Computation expressions) giving curly braces a total new meaning and dignity, for building monadic operations in the best expressive way ever. (see task, async, query, etc..)
Why is scala more popular?
A note on package management:
- package management in JVM(maven) and nodejs(npm) is more complicated...
- package management in NET works like a charm and is amazing, plus nuget is part of the dotnet tooling, not an "external thing" anymore, so dependencies are part of your .fsproj or a line in your script .fsx amazing.
ML was the first lisp-like statically typed programming language,
and OCAML also supported object orientation and imperative construct,
giving the most pragmatic approach to functional programming languages.
This lets you write "like python or javascript" and have strong typing like any strongly typed language.
Pros of F#:
- it's a NET6 language runs everywhere part of the NET6 platform
- has scripting and a repl and can be used like python/nodejs/bash
- has type providers and the |> pipe operator, making it awesome to work with collections and data
- has computation expressions, a very beautiful and simple way to write custom "monadic operations" in F# (not an expert here)
- F#6 supports natively Task
- runs on aspnetcore easilly with beautiful libraries such as Giraffe/Saturn/Falco
- looks much closer to javascript and is much more readeable than scala
- transpiles to javascript with Fable compiler
- is based on many years of academic research and 25+ years of OCAML as is an ocaml implementation for .NET, making it one of the best functional languages available today
- doesnt (yet?) run on the JVM, but is both a .NET language and a node.js language
- has automatic type generalization and everything is curriable
- is supported on very good IDEs: VsCode, Rider, VisualStudio
- is opensource since long time
- influences many languages (like C# and Typescript)
- F# Synthax is more accessible and better as an entry level language too (~python) for people which never started programming
Cons of F#
- doesnt have curly braces for scoping (but has for CEs, no worries!)
- doesnt have Higher order Kinds... Oh No! big drama moment? (btw has generic interfces..)
functional programming langugages that don't force the developer to only use immutable datatypes
- are there any, except maybe toy languages?