For anyone interested in trying out F# online, looks like Microsoft Research has such a tool: 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:
Click on the Intro to F#. Or try the user contributed notebook:
What happens when you click the Intro to F# sample on the front page? It should render the notebook and if you clone, it should prompt to sign in as above. Hope this helps.
EDIT: I'm now able to login. It brought up a little redirect modal after entering my user name which due to my typing was apparently getting canceled. The notebook load, but I get now chart.Plot output.
I haven't used jupyter notebooks much. They seem cool, but not as cool as light tabels insta-repl.
One of the things Go does right is the download-hello-world-compile-run experience. Especially now, since they now default GOPATH. One of the things that Go does wrong for popularity is the opinionated directory structure based environment mechanism. It has some advantages for large programming projects, but the way it runs counter to many programmer's expectations is seen by many as a wat!?
If Go had some way of mitigating that and the lack of generics, then the Hello World experience would be better for more people. (For admittedly shallow reasons, IMHO. I think that Go is pretty good the way it is. I haven't yet felt a need for generics yet in my MMO project.)
Does the lack of generics really impact the experience of "Hello World"? I don't think I've ever seen generics used in a "Hello World" example even in languages that have them.
My issue with the online editors is that it restricts your ability to access files, add dependencies and modify your local machine. If anyone would like an online version I'd be interested to hear why?
The article is actually more of an annotated version of the F# Tutorial Script 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
* Visual Studio for Mac
* Visual Studio Code (via Ionide plugins)
* .NET Core and the .NET CLI (`dotnet new console -lang F#`)
* Azure Notebooks (Jupyter in the browser via Azure) 
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
If there's a feature you want to see, let me know. I take requests.
I might be slightly biased but in my opinion it's one of the best programming articles I have ever read.
Discriminated Unions and pattern mactching still come in handy, the syntax is still less verbose, there is less biolerplate/ceremony than in C# where everything has to be in a class.
it is easier to pass a function to a function than in C#
inlining functions is easier
the type inference can be useful in various ways.
if/then/else statements being expressions is extremely nice.
I tend to code in a mostly imperative style, even in F#. I understand it better, it usually performs better.
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.
So if you want to interact with these great libraries, you have to tolerate a pretty shitty language with annoying tooling at best. So when I want to do something practical, I wind up going that way disappointingly often.
Sometimes the answer is just so obvious to people who have that foundation knowledge that no one else has bothered to ask on reddit/stackoverflow and you are googling into the wind. Sometimes the only thing you can find is several years old and giving advice that's no longer correct. I'm not sure which is worse.
I had the same trouble trying to build a learning project in Clojure. I remember when starting, I had only used pip and apt-get (and not knowing them well), I didn't even recognize Leiningen as a package manager. It worked so differently from what I thought I needed (and billed itself as a "project automation and configuration tool") that I didn't even recognize it was the solution to my problem.
It's just so easy to take for granted how many things are obvious to us that make solving problems in our comfort zone easy for us and paralyzing for another person, and I think this bias finds its way into the documentation and mindset of entire communities. This makes it harder and harder for something to be approachable if you don't fit in that same box. I'd love to love F#, (I read F# for fun and profit and worked through the F# Koans, but haven't made anything), but I'm not sure if I'll ever get over the hump unless I find myself working somewhere that's already using it. My feelings on Python are somewhere between ambivalent and bitter by now, but the work gets done, I know what to expect, and I never feel lost.
What would really help me, I think:
- More "idiomatic" wrapper libraries around .NET libraries, even if they're slower or have less features/customization.
- Pure F# libraries of typical utilities or ports of popular libraries in other languages, even if they are slower or have less features/customization.
- Content about F# project management from the perspective of someone who uses Python. This is how you do it in Python, this is how you do it in F#, this is why, these are the pros, these are the cons, these are just different because that's the way it is.
- There's never a need for "Microsoft" documentation -- you'll have a question with a specific product or service. They really should be distinctive visually.
- This is on the microsoft domain and top left click goes to microsoft.com, but you can't get back here from microsoft.com
- By the time I click through to something (for example, .NET->F#->Get Started), I have not one but two major navbars and footer featuring prominent links and menus completely orthogonal to what I'm viewing. There is nearly zero typographical variation among the content I've expressed interest in (F#), and tons of variation for this separate content. This is distracting.
Honestly, I've always found the .NET(C#) docs pretty good even going into naming conventions and design patterns. However I'm open to improvement as they were looking a bit dated and I often had trouble ending up in docs for older versions of software/OS's.
for line in File.ReadLines("/path/to/file") do
printfn "%s" line
|> Seq.iter (printfn "%s")
|> Seq.iter (fun line -> printfn "%s" line)
You can do so along the way without focusing so much on doing idiomatic FP and achieve both pragmatic and palatable results.
Designing solutions with the type system enabled by F# and it's ability to interop with whole .NET ecosystem is really a powerful combination.
I doubt I would have ever stuck with Clojure longer than a day, for example, if it wasn't for this library. It's not very long and all the functions are very short, but it meant that everything I needed from the file system was a 30s peek at the documentation and exactly what I expected rather than ~30+ minutes futzing with Java and forgetting what I was doing in the process https://github.com/Raynes/fs
Which I keep overlooking with so many years of C#, I'm so sorry about that :(
That being said, looking at the .NET framework documentation and hanging out on fsharp.org's slack might be a good way to make up for what you are missing to get started.
The .NET reference is useful if you are reading through code and maybe to modify it slightly, but I find it (and class hierarchy style docs in general) to be close to useless if you are writing new code and new to the library. Using a new library in Python (especially one that's heavily object oriented), I often find it easier to learn from tests instead of the docs. Reference docs are often inaccurate or too verbose or show no sense of importance or are just poorly written. Tests are straight to the point, include examples, and tend to focus on the most important parts of the library.
The MSDN docs have quite a bit of "How do I..." content, but unfortunately F# is seemingly always blank as an example.
Combine this with a huge proportion of commonly used third party libraries being .NET rather than F# libraries, and so much of the .NET infrastructure you need to use being C# focused, and as a newcomer you are paralyzed.
If F# is serious about building a community of more than just C# converts, they need to recognize that the convenience of .NET for people who already know it carries a commensurate tax for everyone who doesn't. It's harder for me to learn .NET as an F# user than a C# user. It's harder for me to learn to use NuGet as an F# user than a C# user. It's harder for me to learn to use Visual Studio as an IDE with F# than C#. In everyone of these scenarios, you're running up hill because examples and documentation and interfaces are all for the majority, which you won't be.
The best I can offer you right now for F#-specific packages is http://fsharp.org/community/projects/ --and the advice that, if you have questions, ask away! F# people will be, I think, extremely ready to answer any questions because we're desperate to see people use the language. Try the mailing list ( https://groups.google.com/forum/#!forum/fsharp-opensource ), https://fsharp.reddit.com/ and the Functional Programming Slack at fpchat.com (well, this one will be back online in a few days--they recently had some drama, which they settled, but they had to disable new signups to let everyone cool down).
Try Pickering & Eason's Beginning F# 4.0; its intro has a 'Who Is This Book For?' section, which says: 'This book is aimed primarily at IT professionals.... A working knowledge of the .NET framework ... would be nice, but it's not necessary.'
Isn't 4.0 pretty far out of date now?
F# 4.0 is not really out of date. The language is fairly fixed now--apart from fixing buggy behaviour actually.
Part of it is that the general ML syntax is pretty timeless--all ML books share this advantage. As for F# specifically, all the headline functionality--type providers, quotations etc.--has been there for a while. I expect books covering 4.0 to be remarkably future-proof.
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.
I use it instead of Powershell for my own scripts.
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.
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.
"A Worst Case for Functional Programming?"
Previous HN discussion: https://news.ycombinator.com/item?id=7043644
Nearly none of the traditional game-based OOP design patterns map cleanly into F# (or any functional lang for that matter) - I often had to get creative but the results were very interesting.
Take an OOP based game for an example; tracking where your game state is, how it's being mutated, and figuring out exactly what entities have been mutated can be a nightmare. With F# I ended up with a single large data structure to store the game state, and because of F#'s pedantic immutability, it's very easy to find where that game state is modified.
The only issue with the scheme above is that there are some cases where you NEED to store game state as a variable captured by a closure. That might sound really awful, but in practice variables captured by a closure are always read-only, so unless you're replacing that closure, you don't have to worry about some weird mutability sneaking up on you.
Here's my first F# minigame, a mostly-finished breakout clone: https://github.com/bsamuels453/BreakoutFSharp
Here's the second game that uses units of measure - it was supposed to be an asteroids clone but is mostly unfinished: https://github.com/bsamuels453/X81-Prototype
Type declarations for the units of measure/data structures I used: https://github.com/bsamuels453/X81-Prototype/blob/rts/X-81_P...
let mutable greeting = ""
let btn_say_hi = new Button(Text = "Say Hi", Parent = frm_main)
btn_say_hi.Click.Add(fun _ -> greeting <- "Hi!")
I think you can do it in most reasonable statically-typed languages, with a little care. Scala makes automatic conversions a bit easier because it lets users specify them. Like C# actually. You could probably do UoM in C# too.
the developer experience isn't great, it's complicated to install and to get started with and the ecosystem related to web development is quite poor. That's not the case for F# and I really really hope it picks up steam. ML languages are really great when it comes to data modelling, domain driven design, writing algorithms and stuff like that. they are a nice compromise between pure FP and OOP.
There are some nice tools as well: merlin, utop, and friends.
As to the ecosystem, I beg to differ: the ocsigen suite of tools (lwt, server, js_of_ocaml), Core, Bucklescript, etc. They're all amazing, well documented, and open source.
I think both languages are quite nice honestly. F# has become a lot more attractive now that .NET is more readily available on more platforms. I hope it gains more steam too!
> But you get over it.
no you really don't, and you shouldn't.
> As to the ecosystem, I beg to differ: the ocsigen suite of tools (lwt, server, js_of_ocaml), Core, Bucklescript, etc. They're all amazing, well documented, and open source.
Now Compare with .NET ecosysem . I was looking for a good MongoDB driver in Ocaml the other day, didn't any good one.
There's still room for both and they're still both great languages. That F# is quite similar to OCaml is a good thing... it means there must be some good ideas in there. :)
As for a MongoDB driver I found https://opam.ocaml.org/packages/mongo/mongo.0.67.2/ on OPAM in a few seconds. OPAM has been huge.
* how do I read a text file
* how do I write a text file
* how do I download a file using HTTP
However, it's probably not terribly interesting since those are things that exercise the BCL, so any C# example would do to show you how it's done.
People are doing themselves a disservice if they scramble for a collection of cheat sheets since there are so good books available.
There's no better way to invite help from strangers. :)
VSCode plugin: https://marketplace.visualstudio.com/items?itemName=Ionide.I...
VS for 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...
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.
https://www.visualstudio.com/vs/visual-studio-mac/ for mac is pretty good. It's less than visual studio for windows, but still ok. Easy to get started.
Visual Code, this seems a highly preferred option, and a lot of Fsharpers seem to use it, even on windows. The learning curve is a bit higher as it's not an out of the box experience. The trend is to combine it with FAKE, Packet and .NET Core (which I'm finding hard to keep track of).
I'm using VS for windows for F# product development at the moment.
On my Mac I use both visual studio for Mac for just mucking about, and visual code to play around with the toolsets the trendy kids keep advocating.
F# has always had good tooling 'for a functional language' but it looks like we're getting close to good tooling period.
The "elid" intrigued me and I tried to look it up but couldn't find anything. Is this just a typo?
PR out here: https://github.com/dotnet/docs/pull/1584
IIRC you just need to install mono, python, jupyter and 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.
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.
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.
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.
This is sort of a Microsoft M.O.
I recently converted an asp.net web app to dotnet core and was able to run it via nginx to the in built kestrel web server the only problem I had was connecting to an MS SQL server named instance.
Debugging in vscode is coming soon (before rtm), works already in dev version