11 ms·
Tour of F#
- kornish 10y agoOne 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/
- fsloth 10y agoI like this one https://dotnetfiddle.net/ https://dotnetfiddle.net/ (F# needs to be selected as a language)
- tmccrmck 10y agoI like playing with F# in a Jupyter notebook. https://notebooks.azure.com/ https://notebooks.azure.com/
- steego 10y agoIf you want to try an F# to JavaScript compiler. Try Fable: http://fable.io/repl.html http://fable.io/repl.html
- smoothdeveloper 10y agothere is also http://try.websharper.com/ http://try.websharper.com/ for toying with the language and websharper.
- aloisdg 10y agoGlot.io includes F# https://glot.io/new/fsharp https://glot.io/new/fsharp
- smortaz 10y agoA 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 10y agoLiterate 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 10y agoCheck out Xamarin Workbooks* for the C# equivalent. (*): https://developer.xamarin.com/guides/cross-platform/workbooks/ https://developer.xamarin.com/guides/cross-platform/workbook...
- Rapzid 10y agoSadly I'm neither able to clone or open an existing clone for the F# notebook :(
- smortaz 10y agoHmmm... when I click on the Horses link, I see its 3 notebooks, with a blue clone & run button. When clicked, I get prompted to sign in (requires any msft account like outlook, xbox, hotmail, ...). Once you sign in (or create an account), you'll end up in Docker/Jupyter instance with the 3 notebooks. Clicking on the first one and doing a Run All, should give you: http://imgur.com/a/JgcqP http://imgur.com/a/JgcqP 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.
- Rapzid 10y agoWhen I choose to connect to an existing notebook nothing happens. When I choose to clone I get to the login screen by clicking the login button does nothing :| 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.
- DaiPlusPlus 10y agoI tried tryfs.net, but the Hello World sample doesn't work in Chrome: uBlock Origin blocks some scripts, but even after disabling uBlock it still doesn't render anything to the output area, it just flashes.
- stcredzero 10y agoOne 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. 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.)
- saghm 10y ago> If Go had some way of mitigating that and the lack of generics, then the Hello World experience would be better for more people. 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.
- stcredzero 10y agoNo, but if you believe the ramblings of the standard HN commenter who complains about Go, very soon afterwards the lack of generics has driven them to gnashing teeth and rending hair.
- eptcyka 10y agoWhenever I evaluate a language past the hello world stage, I try to do something more complex. Which is where the generics come in. Imagine for a second that I may want a hashmap with a custom key/hash function (most often it would actually be a set) for my own datatype. I can't just use the built in hashmap _language construct_ (the hashmap is it's own, very special type), I either have to write a hashmap implementation myself or wrap a hashmap in it's own type and have custom getters and setters which would extract a key from my custom type that is intended to be stored in the map. It might be more go to do said things, but then it just means that it's more go to write code that is more likely to be buggy.
- finnnk 10y agoYou might also want to look at Pex4Fun which has a bunch of little coding challenges (you'll need to select F# if it isn't already). Hit 'Ask Pex' to get going. http://www.pexforfun.com/Page.aspx#learn/ http://www.pexforfun.com/Page.aspx#learn/
- RyanHamilton 10y agoI've wrote a java REPL that runs locally but can upload to remote: http://jpad.io/example/1E/fetch-headlines-using-jsoup http://jpad.io/example/1E/fetch-headlines-using-jsoup 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?
- davidgl 10y agoA more concise cheat sheet: http://dungpa.github.io/fsharp-cheatsheet/ http://dungpa.github.io/fsharp-cheatsheet/
- oblio 10y agoI 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 * ...
- ygra 10y agoRosetta Code might help there: - http://rosettacode.org/wiki/File_input/output#F.23 http://rosettacode.org/wiki/File_input/output#F.23 - http://rosettacode.org/wiki/HTTP#F.23 http://rosettacode.org/wiki/HTTP#F.23 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.
- riles01 10y agoThat's a great idea. I think most people come to F# knowing a bit of .NET already, so these types of things are often overlooked.
- steego 10y agoThat's a great idea. If you set up a github or wiki, I'd be happy to help out and fill in areas. If you want to get more people to help, market the cheat sheet as "The Right Way". There's no better way to invite help from strangers. :) http://www.phptherightway.com/ http://www.phptherightway.com/
- fsloth 10y agoExpert 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.
- steego 10y agoJust 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.
- agentultra 10y agoSo much like OCaml... but I like the ability to annotate units! That's very cool.
- programLyrique 10y agoThere was as a seminar at Inria yesterday about an extension of OCaml to handle units: http://gallium.inria.fr/seminaires/annonces/20170221.Jacques.Garrigue http://gallium.inria.fr/seminaires/annonces/20170221.Jacques...
- bsamuels 10y agoUnit 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 10y agoHow 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.
- orderlyoctopus 10y agoCurious about this also. Last time I took a peek at F# I wanted to make a simple game, but all the compatible tools seemed like C# tools that allegedly work for F# as well. Wound up using Lua/LOVE instead.
- yawaramin 10y agoYou can do imperative and object-oriented programming with F# :-) Here's an example with a Windows Forms button which modifies a string variable on click: let mutable greeting = "" let btn_say_hi = new Button(Text = "Say Hi", Parent = frm_main) btn_say_hi.Click.Add(fun _ -> greeting <- "Hi!")
- phillipcarter 10y agoAuthor 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/vsintegration/ProjectTemplates/TutorialProject/Template/Tutorial.fsx https://github.com/Microsoft/visualfsharp/blob/master/vsinte... [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.Ionide-fsharp https://marketplace.visualstudio.com/items?itemName=Ionide.I... [4]: https://dot.net/core https://dot.net/core [5]: https://notebooks.azure.com https://notebooks.azure.com
- markdoubleyou 10y agoThe Jupyter notebook hosting on Azure is a wonderful, underrated service. Amazing that they offer it for free.
- halfnhalf 10y agoeven iPad http://continuous.codes http://continuous.codes
- enricosada 10y agoBig :+1: to continuous, the f#/c# ide for ipad, really slick
- melling 10y agoWhat'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 10y agoThere 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.Ionide-fsharp https://marketplace.visualstudio.com/items?itemName=Ionide.I... 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/tutorials/getting-started/getting-started-vscode https://docs.microsoft.com/en-us/dotnet/articles/fsharp/tuto...
- vosper 10y agoWhat'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 10y agoVS 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.
- jackmott 10y agoI can't speak to Visual Studio for Mac, but the Ionide plugin for VSCode is very impressive. VSCode will fire up faster than Visual Studio for windows and use less resources, ionide has some features Visual Studio does not. There are pros and cons, some people hate Visual Studio, some people prefer it. I prefer Visual Studio but Ionide is not bad when I'm in Linux.
- problems 10y agoThe 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.
- vosper 10y agoI had the same feeling with Clojure. I'm not sure it's due to not having a strong functional background; I think it might be the reality of interop between very different languages.
- orderlyoctopus 10y agoDefinitely. Understanding Clojure/Java interop to consume a library requires that you understand both Clojure and Java far more than you would need to if you were to consume a library native to whatever you were using.
- vosper 10y agoThat's one of the reasons I gave up on Clojure, though I think it could be a good option if you're coming from the Java world.
- jackmott 10y agoF# can be a nice language even if you don't care for the functional paradigm. 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.
- smoothdeveloper 10y agoThing is that putting together short helpers for the "nasty" bits often revolve around 1 line helpers. 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.
- jsingleton 10y agoThese 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#.
- illuminati1911 10y agoFor 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-unreasonable/ https://fsharpforfunandprofit.com/posts/is-your-language-unr... I might be slightly biased but in my opinion it's one of the best programming articles I have ever read.
- brianberns 10y ago"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 10y agoMe too, and the whole site is available as a ebook: https://www.gitbook.com/book/swlaschin/fsharpforfunandprofit/details https://www.gitbook.com/book/swlaschin/fsharpforfunandprofit...
- euroclydon 10y agoHow difficult is it to get an F# kernel for Jupyter running on my Mac?
- smoothdeveloper 10y agoIt 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.
- phillipcarter 10y agoNote that you can also run it in the browser via Azure Notebooks, which is free: https://notebooks.azure.com/ https://notebooks.azure.com/
- aashishkoirala 10y agoI 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 10y agoIt'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.
- omni 10y ago> /// 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 10y agoThat'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
- rokob 10y ago+1 I was also intrigued by "elid", the other response to this comment solved the mystery.
- ice109 10y agodoes anyone know what the state of C/F# on Linux is?
- sigstoat 10y agoF# works fine for me on linux. what is it you're after?
- ice109 10y agowell 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 10y agoF# 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.)
- knocte 10y agoWe (https://news.ycombinator.com/item?id=13541679#up_13548091 https://news.ycombinator.com/item?id=13541679#up_13548091) use F# in Linux and works very well.
- rjblackman 10y agoIt works very well, it's partly about microsoft ditching a lot of dependency on windows and giving open source developers what they have had for a while with ruby/python/java (think gem packages, ability to run build tasks etc easily via a command line interface) etc. 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.
- 10y ago
- ultrahate 10y agoI 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 10y agoEdit: 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.
- knocte 10y agoI 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
- markatkinson 10y agoSo 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.
- pjmlp 10y ago> I wish there was a way I could do more F# at my work. I use it instead of Powershell for my own scripts.
- brianberns 10y agoI 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).
- aweb 10y agoI 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#!
- vatotemking 10y agoMe 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 10y agoI don't know about any direct links, but they both have a common ancestor in Ocaml.
- steveklabnik 10y agoNot much directly, but they both took a lot of inspiration from OCaml, so that'd make sense! A family resemblance.
- xvilka 10y agoI 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 10y agoPluses include mulithreaded concurrency and access to .NET libraries (including interop to/from your employer's proprietary C# code).