
F# for Fun and Profit - rajadigopula
https://www.gitbook.com/book/swlaschin/fsharpforfunandprofit/details
======
faccacta
What I appreciate about books like this is that they assume the reader is
already familiar with programming, and so the book cuts to the chase and
explains why this language is unique and how it is different from the
languages the reader probably already knows. The author was smart enough to
know that very few students of F# will have picked F# as their very first
introduction to programming, so this makes a lot of sense. I get frustrated
with programming language tutorials that take the opposite approach and expend
multiple screenfuls carefully explaining what a variable is.

~~~
SadWebDeveloper
f* yeah lots of tutorials and books start saying "do as i say, write
everything i ask you to do, i know more than you noob" specially those made by
the author of "learn * the hard way".

~~~
cholantesh
Zed Shaw is specifically targeting beginners though.

------
KurtMueller
I've been getting into F#, specifically for Monogame & Unity, and Scott's
website, blog, and videos have been incredibly helpful in introducing F# and
highlighting the strengths of the language.

I currently only use F# for fun and games. I hope to use it for an upcoming
project however.

~~~
20yrs_no_equity
What are the limitations of using F# with Unity? Do you have full access to
the Unity APIs? Can you write F# scripts and have them run in WebGL or iOS
deployment targets? How does it work?

F# might just be the thing I'm looking for. And I love the idea of functional
programming in unity.

~~~
benrjackson
Currently you can't target iOS, Windows store & WebGL with F#. For these
platforms Unity uses an IL to C++ transpiler which doesn't work with F#. This
might change in the future (one of the Unity devs submitted an IL2CPP issue in
the F# github repo a few weeks back).

Desktop platforms work fine.

F# doesn't have the Unity editor and project support that C# & UnityScript
have. In practice this isn't much of an issue.

There are few things to be mindful of:

1\. The F# target platform must be changed to Unity's .net 3.5 equivalent.
Similarly, full framework support must be enabled in Unity.

2\. VS debugger support requires turning off optimisations and running a post
build step to convert between Microsoft's pdb format and Mono's mdb. The
debugger itself is actually far more stable for F# than for C#. 3\. Unity
profiler support requires adding the compilation symbol 'ENABLE_PROFILER' to
the F# project.

~~~
danbolt
I've heard that the Mono runtime in Unity is a bit old and doesn't support
tail calls as some of the newer stuff.

I haven't had much luck finding concrete evidence though. Is this an issue
with Unity and F#?

~~~
benrjackson
The Mono runtime Unity uses is, I think, a fork of Mono 2.8. The tailcall op
wasn't implemented in Mono until 2.10 (again, I think). The tailcall op is
essentially ignored by Unity Mono.

To date, we haven't had a single stack overflow in our 10k LOC app.

I should mention that the style of programming we are using is alot more
imperative than the typical F# program. Any potentially large collection is an
Array, C# list or Dictionary. F# immutable lists (and maps) are still used in
most areas where data sizes are known to be small and allocations are not so
important.

The Mono runtime used by Unity has a very inefficient non generational garbage
collector (conservative Boehm). A generational GC wasn't introduced until 3.x.
Unfortunately this tends to lead to a less functional and more 'allocate once
and reuse' style.

The Mono JIT also produces code which is often an order of magnitude slower
than MS .net (which itself is slower than coreclr).

Despite these caveats - a significant proportion of code can be written in a
purely functional style and good performance can still be achieved.

~~~
danbolt
That's exciting to know. I hope to give F# and Unity a try sometime soon,
then!

I remember the XNA C# runtime on the Xbox 360 required similar strategies with
memory as well. It's nice to see garbage collectors improve as time goes on.

------
douche
This is fantastic. I like the progression in the table of contents. Something
similar on the website might be helpful - it is packed chock full of useful
information and great tutorials, but could perhaps use a little better
organization.

~~~
rajadigopula
Agree. This is only a gitbook made out of the blog. I have been eagerly
waiting for the eBook from the author @
[https://leanpub.com/understandingfunctionalprogramming](https://leanpub.com/understandingfunctionalprogramming)

------
vathymut
Both the book and his talks are fantastic resources.

~~~
verinus
and I might add the website
[http://fsharpforfunandprofit.com/](http://fsharpforfunandprofit.com/) . it
sold me on f#. really good explanations and ideas.

edit: typo edit 2: well I was a bit too eager to add the website just to find
it to be the base for the linked GitBook- my bad- I just appreciated the
content so much ;)

------
qaid
I do F# full-time at work, and I program with it for fun too. I'm a big fan of
the language, and I think this site helped me make the full switch from C#.
I've long been hoping for an ebook version--I must've printed out half of this
site the last time I went on an international flight!

~~~
KurtMueller
You use F# full-time at work? May I ask what you do?

~~~
qaid
Sorry for the late response. I work in the utility industry writing internal
web applications. Before I started, my former lead convinced our manager (who
is generally hands-off) to let him work in F#

~~~
KurtMueller
Did you know you were going to do F# coming into the position? Or did you
start up while you were there?

------
artmageddon
Is it just me, or are the links at [0] broken? That is, when you try to click
through some of the examples such as "Use F# to explore the .NET framework
interactively"?

[0]:
[https://swlaschin.gitbooks.io/fsharpforfunandprofit/content/...](https://swlaschin.gitbooks.io/fsharpforfunandprofit/content/series/low-
risk-ways-to-use-fsharp-at-work.html)

~~~
edgyswingset
Every link on that page worked for me.

~~~
artmageddon
Ok - must be our stupid web filters at work. Thanks!

------
dnos
I've recently been playing with F# on the side to learn more about functional
programming and his website version has been a key part of what has kept me
going. It's good to see an easy-to-read ebook version!

F# is impressive and so is the website. I highly recommend reading this if you
are interested in F#/functional programming.

------
kayla210
Very interesting! This is also my first time hearing of GitBook. Thank you for
the link!

------
usloth_wandows
When I used F#, maybe three years ago, it was a good exercise in functional
thinking. It was an interesting experience, siniliar to the experience of
using C-Lisp. The worst part was the lack of documentation and community.

~~~
fsloth
The main usable documentation is in the book Expert F# by Don Syme et all
which demonstrates how to use all the nifty language features for real life
code. I think it's a pattern with nearly all Microsoft products - you need to
buy training (e.g. in the form of book) to use them properly.

