
Tour of F# - dimitrov
https://docs.microsoft.com/en-us/dotnet/articles/fsharp/tour
======
kornish
One observation from watching Go and Rust gain popularity is that having an
online code evaluation tool like [https://play.rust-
lang.org/](https://play.rust-lang.org/) or
[https://play.golang.org/](https://play.golang.org/) can do wonders for
adoption. People can experiment in a sandbox without having to hop into a
development environment, and peers have an easier time debugging by easily
sharing and reproducing problems.

For anyone interested in trying out F# online, looks like Microsoft Research
has such a tool:
[http://www.tryfsharp.org/Create](http://www.tryfsharp.org/Create).
Unfortunately looks like you have to create an account of some sort to share
scripts, so these alternatives might be better:

[https://repl.it/languages/fsharp](https://repl.it/languages/fsharp)

[http://tryfs.net/](http://tryfs.net/)

~~~
smortaz
A more recent Microsoft offering for trying F# (or Python, R) is:

[https://notebooks.azure.com](https://notebooks.azure.com)

Click on the Intro to F#. Or try the user contributed notebook:

[https://notebooks.azure.com/library/HorsesForCourses](https://notebooks.azure.com/library/HorsesForCourses)

[msft]

~~~
sremani
Literate Programming with Notebooks is where no other .net based language
comes close to F#. I will spend more time on F# notebooks, this is great!

~~~
t1amat
Check out Xamarin Workbooks* for the C# equivalent.

(*): [https://developer.xamarin.com/guides/cross-
platform/workbook...](https://developer.xamarin.com/guides/cross-
platform/workbooks/)

------
phillipcarter
Author of the article here. Happy to see this up on HN!

The article is actually more of an annotated version of the F# Tutorial
Script[0] which ships inside Visual Studio 2017 (also in other version of
Visual Studio, but the Tutorial script is a bit different there).

You can get started with F# just about everywhere everywhere:

* Visual Studio[1]

* Visual Studio for Mac[2]

* Visual Studio Code (via Ionide plugins)[3]

* .NET Core and the .NET CLI (`dotnet new console -lang F#`)[4]

* Azure Notebooks (Jupyter in the browser via Azure) [5]

[0]:
[https://github.com/Microsoft/visualfsharp/blob/master/vsinte...](https://github.com/Microsoft/visualfsharp/blob/master/vsintegration/ProjectTemplates/TutorialProject/Template/Tutorial.fsx)

[1]: [https://www.visualstudio.com/vs/visual-
studio-2017-rc/](https://www.visualstudio.com/vs/visual-studio-2017-rc/)

[2]: [https://www.visualstudio.com/vs/visual-studio-
mac/](https://www.visualstudio.com/vs/visual-studio-mac/)

[3]:
[https://marketplace.visualstudio.com/items?itemName=Ionide.I...](https://marketplace.visualstudio.com/items?itemName=Ionide.Ionide-
fsharp)

[4]: [https://dot.net/core](https://dot.net/core)

[5]: [https://notebooks.azure.com](https://notebooks.azure.com)

~~~
halfnhalf
even iPad [http://continuous.codes](http://continuous.codes)

~~~
enricosada
Big :+1: to continuous, the f#/c# ide for ipad, really slick

------
steego
Just a reminder: Scott Wlaschin's book, F# for fun is a great free resource
for people interested in F#. It's available here:
[https://fsharpforfunandprofit.com/](https://fsharpforfunandprofit.com/)

If you have a short attention span, I recently started posting sped up
screencasts on twitter that range between 1-2 minutes.
[https://twitter.com/FSharpCasts](https://twitter.com/FSharpCasts)

If there's a feature you want to see, let me know. I take requests.

------
illuminati1911
For anybody curious/interested in F# or any programmer who is interested in
safe (functional) programming, check this out:

[https://fsharpforfunandprofit.com/posts/is-your-language-
unr...](https://fsharpforfunandprofit.com/posts/is-your-language-
unreasonable/)

I might be slightly biased but in my opinion it's one of the best programming
articles I have ever read.

~~~
brianberns
"F# for fun and profit" is a great site. This was one of my main sources of
information when I was making the switch from C# to F#.

~~~
davidgl
Me too, and the whole site is available as a ebook:
[https://www.gitbook.com/book/swlaschin/fsharpforfunandprofit...](https://www.gitbook.com/book/swlaschin/fsharpforfunandprofit/details)

------
problems
The problem I had going into this without a strong functional background is
that often times to do practical things you're forced to work with .NET
libraries - these .NET libraries are not nice functional libraries and don't
encourage you to think functionally. Eventually I felt like everything I wrote
was wrong and I just gave up on it.

~~~
pmarreck
Sounds like the same issue I had with Clojure and Scala. As soon as you touch
anything Java or mutable, it's like WTF?

Come to the Elixir/Erlang camp; our functional turtles go all the way down!
The only jarring thing is having to write to a mutable database. They even
borrowed the |> operator! And it has great pattern matching of course.

~~~
davidgl
Or use both:
[https://www.youtube.com/embed/HLs6WgAmX64](https://www.youtube.com/embed/HLs6WgAmX64)

~~~
pmarreck
Holy crap. Interesting!

------
markatkinson
So I learned F# and C# in parallel. But more emphasis on F# than on C#, and so
when I landed my first dev job on C# I was so incredibly baffled at the code
base. I would toss my arms up in shock at the sight of reference types or
classes being passed around and updated from external methods. The horror! How
could somebody do this.

Anyway, now I have come to learn it is just another way of doing things but my
C# programming style is heavily influenced by a more functional style. I never
realised till I actually landed a job where I had to interact with more
standard OOP principles.

I wish there was a way I could do more F# at my work.

~~~
brianberns
I learned C# (and OOP in general) first, and then made the switch to F# (and
FP in general). F# does a great job combining the two paradigms, IMHO, and is
a pleasure to work with. I hope I never have to go back to C# (although they
keep adding new FP features to it in every release, so it's not as bad as it
used to be).

------
jsingleton
These is also FAKE (F# Make), a DSL for build tasks
([https://fsharp.github.io/FAKE/](https://fsharp.github.io/FAKE/)). Similar to
CAKE ([http://cakebuild.net/](http://cakebuild.net/)), which uses C#.

------
aashishkoirala
I know it's already been mentioned, but I just wanted to endorse
[https://fsharpforfunandprofit.com/](https://fsharpforfunandprofit.com/) again
- you could not ask for a better teacher than Scott Wlaschin if you want to
learn F#.

~~~
yawaramin
It's a great resource for F#. If you also want to get really strong in
functional programming fundamentals I highly recommend taking Prof. Dan
Grossman's free online course [https://www.coursera.org/learn/programming-
languages/](https://www.coursera.org/learn/programming-languages/) \--he's a
great teacher and the subject matter is great for all levels of experience.

------
agentultra
So much like OCaml... but I like the ability to annotate units! That's very
cool.

~~~
bsamuels
Unit annotation is F#'s secret killer feature.

I did a small video game in F# using unit annotation and was shocked at the
number of bugs that unit annotation picks up at compile time.

If you work with a lot of unit conversions (pixels, inches, whatever), I
highly recommend giving F# a shot on a small project.

Unit annotation + access to the .NET ecosystem has made this language a
personal favorite for any project heavy with numbers.

~~~
sp33der89
How was your experience with F# and game development? I like F#'s syntax so
much more than C#(plus some stuff like pattern matching are so nice). However
I feel like FP isn't effective for gamedev.

~~~
agentultra
> However I feel like FP isn't effective for gamedev.

Oddly, in my limited experience, it is very effective.

I can't say it's the right pattern for every game but for the current
roguelike I've been working on in my spare time it's been the best thing since
sliced bread. I use the Reader and State Transformer monads in a pattern
similar to the Elm Architecture that results in my engine being completely
deterministic.

This allows me to dump all of the initial state of the game and all of the
serialized inputs to it. I can then take that dump and step through that
entire game session. This is great for debugging with friends and stuff: when
they encounter an error or something they don't like they can just send me the
dump file and I can replay their entire session. It's been pretty cool being
able to do that.

Another thing I didn't understand at first was that immutability seemed like
an egregious waste of resources. It might still be for some applications but
it has much better performance characteristics than my intuition had led me to
believe... because structural sharing. You can have this big blob of state
that looks like it's being copied every where but it's not -- under the hood
you're actually sharing 99% of the previous state and not copying anything.

It's not likely you're going to be writing a bleeding-edge rendering engine in
a pure FP language on any current generation hardware platforms but you can
get quite far with it.

~~~
vog
Obligatory prog21 article on that topic:

"A Worst Case for Functional Programming?"

[http://prog21.dadgum.com/189.html](http://prog21.dadgum.com/189.html)

Previous HN discussion:
[https://news.ycombinator.com/item?id=7043644](https://news.ycombinator.com/item?id=7043644)

------
knocte
I hope this is not flagged as spam but I think another good way of learning F#
is getting paid to write it :) see
[https://news.ycombinator.com/item?id=13541679#up_13548091](https://news.ycombinator.com/item?id=13541679#up_13548091)

------
davidgl
A more concise cheat sheet: [http://dungpa.github.io/fsharp-
cheatsheet/](http://dungpa.github.io/fsharp-cheatsheet/)

~~~
oblio
I don't know if there's such a thing (maybe I should write one myself, as I
plan to learn F# :) ), but a cheat sheet that is a bit higher level would be
useful.

Things like:

* how do I read a text file

* how do I write a text file

* how do I download a file using HTTP

* ...

~~~
fsloth
Expert F# by Don Syme et. all is a fantastic book for precisely this purpose.

People are doing themselves a disservice if they scramble for a collection of
cheat sheets since there are so good books available.

~~~
runevault
Can you go straight to this book or do you need to get a certain comfort level
with f# first? I have the latest edition for F# 4 but haven't read it yet,
plan to as part of my learning the language but haven't figured out order.

~~~
fsloth
It's pretty good.

~~~
davidgl
I certainly looked at the cheat sheets, played around a lot, read lots of
online tutorials. Only once I had a basic understanding did I read Don's
Expert F#, its great, but not for beginners.

------
xvilka
I wonder, what are the pluses of F# that missing in more mature and widely
adopted OCaml? Why to create a clone of good language? With porting opam to
Windows platform [1], along with improving the Unicode support [2] in it I'd
say it has a bigger potential in this field.

[1]
[https://github.com/ocaml/opam/issues/2191](https://github.com/ocaml/opam/issues/2191)

[2]
[https://github.com/ocaml/ocaml/pull/153](https://github.com/ocaml/ocaml/pull/153)

~~~
spiffytech
Pluses include mulithreaded concurrency and access to .NET libraries
(including interop to/from your employer's proprietary C# code).

------
melling
What's the quick start for using F# on the Mac? Can I get a good native
development environment? Am I better off running a Windows VM to get better
tooling?

~~~
phillipcarter
There are multiple ways to use F# on the Mac. I use both Visual Studio Code
with Ionide and Visual Studio for Mac.

VSCode plugin:
[https://marketplace.visualstudio.com/items?itemName=Ionide.I...](https://marketplace.visualstudio.com/items?itemName=Ionide.Ionide-
fsharp)

VS for mac: [https://www.visualstudio.com/vs/visual-studio-
mac/](https://www.visualstudio.com/vs/visual-studio-mac/)

There is a guide for VSCode + Ionide here: [https://docs.microsoft.com/en-
us/dotnet/articles/fsharp/tuto...](https://docs.microsoft.com/en-
us/dotnet/articles/fsharp/tutorials/getting-started/getting-started-vscode)

~~~
vosper
What's the difference between VSCode and Visual Studio for Mac, for developing
F#? What's the reason that you find yourself using both? I thought it would be
preferable to just have one IDE.

~~~
phillipcarter
VS for Mac is a full-on IDE, is significantly larger, and comes with lots of
stuff to build a variety of apps.

VSCode is a text editor that, combined with the Ionide plugins, gives you a
great lightweight IDE-like experience. It requires a bit more setup, but it's
great if you prefer a more lightweight experience but still want a bunch of
great features.

I use both depending on what I'm doing or what I feel like using. Typically
I'll use VSCode for smaller projects or one-off F# scripts, but you can use it
for just about anything. Ionide itself is actually built using Ionide, so
that's a great example of using it for something bigger.

------
aweb
I know that it's not entierely related to the post, but is there a specific
job board for F# jobs? I tried the language a bit and really liked it but it
seems to be rarely used in a professional setting, which is a shame... I'd be
interested to know where I could potentially find a job where I could use F#!

------
omni
> /// Conditionals use if/then/elid/elif/else.

The "elid" intrigued me and I tried to look it up but couldn't find anything.
Is this just a typo?

~~~
phillipcarter
That's a typo! Thanks, I'll get that fixed.

PR out here:
[https://github.com/dotnet/docs/pull/1584](https://github.com/dotnet/docs/pull/1584)

------
vatotemking
Me while looking at the examples: Hmm F# looks like an easier version of Rust.
I wonder how much of Rust was inspired by F# (since F# is older).

~~~
mcguire
I don't know about any direct links, but they both have a common ancestor in
Ocaml.

------
euroclydon
How difficult is it to get an F# kernel for Jupyter running on my Mac?

~~~
smoothdeveloper
It became easier recently with droping a dependency on libgdiplus.

IIRC you just need to install mono, python, jupyter and ifsharp:
[https://github.com/fsprojects/IfSharp](https://github.com/fsprojects/IfSharp)

All but last one should be on brew, for last one, you should be able to build
it out of box with mono installed.

Don't hesitate to report issue on the repository if that fails.

------
ultrahate
I realize that .NET is F#'s biggest strength from the perspective that
Microsoft probably holds of trying to push C# more functional, and trying to
attract talent from R, Ocaml, Rust, Julia, Haskell, etc, but it also feels
like its biggest weakness.

I'd love to see some sort of bootstrapped version that makes use of .NET
Native or CoreRT or whatever they use today, and I'd REALLY like to see a
strong Stdlib for F# that takes into account what functional programmers are
used to.

I've been doing functional programming for several years, and I feel like a
moron working with F# because I don't know half of these dumb .NET classes and
some of the domain problems don't really leave me able to budget enough time
to bootstrap my own solutions OR learn all the .NET stuff I need. Especially
not when I can jump into several other languages and have a working prototype
often in days or hours.

~~~
ultrahate
Edit: just before somebody starts whining about it, I ain't got no problems
with NET on its own, but the barrier to proficiency in it from a functional
universe is needlessly high, and if F# had a stronger core it would be
something non NET programmers could pick up along the way rather than
continuously bash their heads into while doing rather menial work.

I don't want to sound whiny either but it's such a punch in the gut when
someone sees me struggling with basic FP stuff in F#, just because I guess I'm
so proud of what I've learned about FP in other languages.

There's also some stuff that F# is missing, but it hasn't screwed me yet
because I still haven't figured out enough about all the NET classes.

~~~
smoothdeveloper
What is needed is new blood among F# users, not coming from C# background and
not too snob about F# not having most advanced type system when compared to
Haskell or other similar ML languages.

Then, effort on making functionally orientated base libraries (without relying
on baking those things in FSharp.Core, but as set of small libraries) wrapping
undelrying .NET APIs, taking inspiration from what is there in Haskell and
other similar languages.

Most F# users today are fine relying on mostly .NET libraries + fresher F#
libraries, but most projects will be done with a mix of paradigms (which is
manageable in F#) which is not most appealing to people with significant FP
background.

~~~
ultrahate
I agree mostly but I'd argue that most F# devs are coming from c# to begin
with. I'd love to see some data suggesting otherwise, but I have a very strong
feeling that its true. I also like multi paradigm, doesn't take away from F#
at all, but it's something that doesn't mix well with developers not familiar
with the NETverse

------
ice109
does anyone know what the state of C/F# on Linux is?

~~~
sigstoat
F# works fine for me on linux. what is it you're after?

~~~
ice109
well i mean there's all this stuff i vaguely see about .NET Core not being as
good as the offering on windows but that eventually it will be? i don't know
C# but i'm interested. i guess i'm just wondering if i should make the leap to
starting to learn it even though i develop solely on linux.

~~~
profquail
F# works well on Mono, well enough to start learning/developing on until .NET
Core gets to real production-grade status on Linux. (I've only toyed with .NET
Core on Mac/Linux - it worked well enough for some simple stuff - but haven't
tried to run any heavy apps on it yet.)

