12 ms·
What I wish I knew when learning F#
- dunefox 5y agoI like F# quite a bit, but the main selling point for me besides my algorithm stuff would be data science/ML. Sadly, the F# libraries like the R Type Provider, JSON Provider, etc. don't seem to work.
- codingclaws 5y agoThis is off topic. I can't resist - that's the thickest sticky header I've seen from a developer.
- gorgoiler 5y agoYes, hah, I too was impressed with the chutzpah of having… “DANIEL” …on a substantial amount of my screen throughout the whole read.
- AlbertCory 5y agoThat it's the same as Gb (on a piano or fretted instrument)? (Sorry. Couldn't resist.)
- 7thaccount 5y agoThe biggest for me is needing to understand the .NET ecosystem without knowing C#. Then there's the lack of beginner information. I own several F# books and none of them assume you're coming from a scripting language background. I eventually gave up for good. OCaml doesn't have the .NET problem, but I found it to be unergonomic in a lot of ways. Make no mistake, it's a cool language that I'd love to be good at. The code always looks elegant, I'm just terrible at writing it.
- orra 5y agoAh, that's interesting. I'm a huge fan of F#, but I had the advantage of knowing .NET first.
- Decabytes 5y agoThis was my issue when trying to learn clojure as well
- billfruit 5y agoYes, my experience as well. Clojure is more "lisp for java programmers" than "java for lisp programmers". Most of introductory material I found was good in explaining functional concepts, lisp approach to solving problems etc, but I thought assumed a working knowledge of the JVM ecosystem. For someone utterly unfamiliar to Java/JVM world would find clojure extremely baffling, cryptic error messages, needing to be familiar with the rather large java standard library, etc.
- 7thaccount 5y agoSame. F#, Clojure, Scala, & Kotlin have all been the same for me. Python's VM is written in C, but I have no reason to know C. In Clojure they have you call out to Java libraries a ton. Someone always tells me that this isn't true on here, but it was my experience as well. Having to learn so many tools like emacs or CIDRE or Leinegen was also a turn off.
- gorjusborg 5y agoI really love Clojure, but I have a lot of experience on the JVM so I didn't have to climb multiple learning curves simultaneously. While the clojure ecosystem has a lot of wonderful, bright and helpful people in it, and clojure itself is technically impressive (esp. its collections implementation), the new user experience isn't great. I'm not an experienced emacs user, so that makes it doubly difficult, as the ironed-out workflows seem to assume that you are (which is fair, as emacs and lisp are like peanut butter and jelly). However, these days it's fair to assume that a new clojure user is probably learning 'clojure', 'lispy ways', 'java/jvm', and 'emacs' simultaneously. I think that calva/vscode has a lot of potential to drop emacs off that list, which is welcome, as its learning curve alone is legendary. If you look at that list, it should not be surprising that the community is small. There's so much to learn that I it seems too much to even start.
- DeathArrow 5y agoThere are several good books like: https://www.amazon.com/Stylish-Crafting-Elegant-Functional-Code/dp/1484239997/ https://www.amazon.com/Stylish-Crafting-Elegant-Functional-C... and https://www.amazon.com/Get-Programming-guide-NET-developers/dp/1617293997 https://www.amazon.com/Get-Programming-guide-NET-developers/... and also some courses on Udemy like: https://www.udemy.com/course/fsharp-from-the-ground-up/ https://www.udemy.com/course/fsharp-from-the-ground-up/ and https://www.udemy.com/course/hands-on-f-application-development/ https://www.udemy.com/course/hands-on-f-application-developm... Also there are lots of learning resources here: https://fsharp.org/learn/ https://fsharp.org/learn/ some for guys coming from scripting languages like Python. As a matter of fact, F# can be used for scripting, too.
- 7thaccount 5y agoI'm not saying that you can't write an F# script, but that the path to getting one written is not obvious to those coming from scripting languages that are much simpler than the VAST .NET & JVM ecosystems. There is always some bizarre .NET arcana that gets in the way.
- akra 5y agoSometimes that's true but I've found as soon as I need packages things get complex. I don't find F# that hard scripting wise; at times found it easier than some other languages especially when I need to import libraries into my script. Instead of needing to install a system wide pip package, set up a project with Maven/Gradle, etc around the script, etc. With F# and the like you just do something like: #r "nuget: FSharp.Data" And it pulls that third party package into your script context. Its kind of empowering when I can just copy and paste script text to my colleague (e.g. email/slack) and all they need to do is copy/paste the text into a single text file and it just works third party packages included with a vanilla .NET 5+ installation. Just run 'dotnet fsi scriptFile.fsx`. Auto-complete picks up all the new types as well. Documentation seems pretty straightforward to me: https://docs.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/ https://docs.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-...
- barrenko 5y agoKinda agree, but F# works much better for me with my knowledge of .NET than e.g. Clojure with my understanding of Java. It's a cliche saying, but for me F# just works! (tm)
- phillipcarter 5y agoThere's definitely room for a book or blog series along the lines of "F# for python programmers" or something. Unfortunately there's some level of .NET tooling you need to understand before you can do much today, and several .NET concepts creep in with that. The good news is that .NET Interactive is shaping up to be a great way to avoid most of that. At least so far all you need to do is install the .NET SDK, then install a VSCode plugin and you're good to go - just write code like you would in a python notebook, and acquiring packages is even easier than in Python: https://github.com/dotnet/interactive#notebooks-with-net https://github.com/dotnet/interactive#notebooks-with-net
- dharmaturtle 5y agoLinking your demo of VS Code Notebooks cause it was great: https://youtu.be/_QnbV6CAWXc?t=1298 https://youtu.be/_QnbV6CAWXc?t=1298
- devmunchies 5y agoI had the exact same problem. Even all the http servers had a lot of .net boilerplate to get started. A lot of that should be abstracted. I built an http server library that abstracts the .net parts. https://wiz.run/ https://wiz.run/ The hello world server: open Wiz.Server open Wiz.Context open Wiz.Route let myHandler ctx = ctx |> sendText "Abra Kadabra Kalamazoo!" let myRoutes = [ get "/" myHandler ] genServer() |> setRoutes myRoutes |> run
- devmunchies 5y agothinking more about it, F# needs to appeal to non-dotnet developers and other developers looking for a functional language for real workloads. F# currently seems easiest for c# dev to get started, but c# devs have almost no incentive to do so.
- SBArbeit 5y agoI could say the same thing about any language. For instance: "Python needs to appeal to C# developers and other developers... Python seems easiest for PHP devs to get started, but C# devs..." And, the truth is, no, Python doesn't need to do that at all. It just has to be the best Python it can be.
- xhevahir 5y agoUsing Python doesn't require you to learn a (big) second language before you can do anything useful, though. F# arguably does. Maybe that is the best F# that F# can be. Which, for a lot of people, is not good enough.
- devmunchies 5y agoI was thinking as a conscious strategy that would impact the way all libraries are built. In my example I posted above, there are no dotnet APIs showing. Its all abstracted. Libraries should create new APIs that are just wrappers around the dotnet library. Whereas, if you look at the examples in the Giraffe framework, you need to do a bunch of dotnet boilerplate. https://github.com/giraffe-fsharp/Giraffe#doing-it-manually https://github.com/giraffe-fsharp/Giraffe#doing-it-manually open System open Microsoft.AspNetCore.Builder open Microsoft.AspNetCore.Hosting open Microsoft.Extensions.Hosting open Microsoft.Extensions.Logging open Microsoft.Extensions.DependencyInjection open Giraffe let webApp = choose [ route "/ping" >=> text "pong" route "/" >=> htmlFile "/pages/index.html" ] type Startup() = member __.ConfigureServices (services : IServiceCollection) = // Register default Giraffe dependencies services.AddGiraffe() |> ignore member __.Configure (app : IApplicationBuilder) (env : IHostEnvironment) (loggerFactory : ILoggerFactory) = // Add Giraffe to the ASP.NET Core pipeline app.UseGiraffe webApp [<EntryPoint>] let main _ = Host.CreateDefaultBuilder() .ConfigureWebHostDefaults( fun webHostBuilder -> webHostBuilder .UseStartup<Startup>() |> ignore) .Build() .Run() 0
- Multicomp 5y agoI am building a tabletop game trainer for Star Wars FFG as the RPG Sessions app is incomplete and trying to do all of the things manually or remember every rule + every modifier to the rule + what all of my NPCs stats are is impossible, and thus when one looks things up, it slows down gameplay a lot, especially during battles. Since the whole point of the system is to make battles feel fast and cinematic, and we want to strictly adhere to the rules as written so we are not constantly re-adjudicating (read: bickering over) house rules, we need something more. Enter F#. I've been working on (yet not releasing a usable version yet bc I'm bad) this program entirely in F#, using Giraffe as the web layer, following the general architecture defined in Domain Modelling Made Functional, and using Dapper to write to a Sqlite database. F# is amazing. I'm able to fully understand the codebase and follow exactly what happens from HTML Form request, through input validation, through the business logic, down to the database and back to the domain, then rendering out to a JS-free webpage via Giraffe. It gets tedious doing the marshalling/unmarshalling from HTML form to input DTO to domain type to output DTO to database records to input DTO etc. and I need to learn both how to create DSLs (so users can type in rules from the book and the system will extract the keywords and compose them into the closest equivalent set of conditions and effects the system supports) and lock down my bounded contexts so I'm developing them in order of least to most entity dependencies rather than in order of where I feel I need them most, but I can't see a way where I would be able to build this in plain old C# without all of my above challenges + lots of boilerplate code to ensure my expected invariants are met and someone (me) hasn't changed an invariant out from under me somewhere else without realizing it.
- 2mol 5y agoYeah, those boundaries between beautiful domain type <-> DTO <-> database is also something my team and I struggle with. In the end we're happy with just writing it out, but there is this nagging feeling that it could be more ergonomic. I'd be interested to hear about other approaches. You could in theory just dump (automatically generated) JSON to the database and evolve your types with tagged versions, but then you have to write some boilerplatey converters between TypeV1, TypeV2, TypeV3, ... I guess that's the price for staying away from full-blown ORMs? It reminds me a bit of how in Elm you just suck it up and write the JSON en-/decoders by hand. Annoying at first, but then you get super obvious and maintainable code out of it, which is quite a joy.
- muglug 5y ago> It has a scripting mode where compilation is done on the fly. This makes it look and feel very similar to python but you still get type checking and much better performance. This is a really wonderful quality in a compiled language. I wish there were more languages with this attribute (but it’s a lot to ask for).
- BBC-vs-neolibs 5y agoCrystal, the compiled-but-super-fast statically typed Ruby dialect.
- nestorD 5y agoThat feature was actually inherited from Ocaml. Both have a REPL and type inference powerful enough to insure that you never indicate types in Ocaml and rarely in F#. The experience is close to having an elegant Python with types, definitely worth becoming more popular.
- DeathArrow 5y agoThe only thing F# has in common with Python is that it is a simple language. Other than that they are different paradigms.
- ur-whale 5y agoIs there a FOSS compiler for F#?
- gameswithgo 5y agothe Microsoft .net core compiler is FOSS, but if that doesn't count there is also mono.
- BBC-vs-neolibs 5y ago... to be clear, Mono does not provide F#. Microsoft releases F# for Mono.
- UK-Al05 5y agoF# and .net core are completely open source. You don't need mono.
- ur-whale 5y ago> the Microsoft .net core compiler is FOSS Oh, I didn't know that. Very cool. Can I apt-get the toolchain? [EDIT]: and for those interested, here's the github repo: https://github.com/dotnet/fsharp/ https://github.com/dotnet/fsharp/
- DeathArrow 5y agoYes, you can.
- ur-whale 5y ago> Yes, you can. I can indeed. apt-get install fsharp (although it pulls in 300MB of dependencies :( ) This is great. How times have changed!
- chusk3 5y agoI wouldn't do this, as this is the mono bundle of fsharp. The blessed/supported way to go now is to install the dotnet-sdk packages[1] and then use `dotnet fsi` for interactive work, and `dotnet build/run/etc` for project-based work in F#. 1: https://docs.microsoft.com/en-us/dotnet/core/install/linux-debian https://docs.microsoft.com/en-us/dotnet/core/install/linux-d...
- mickjagger 5y agoWhat does F# do that other languages don’t? What it’s unique benefit?
- de_keyboard 5y agoIt's the combination of features which is killer. I don't know of another language that offers all of these: - Expression orientated - Lightweight syntax - Emphasis on immutable data and pure functions - do-notation (in F# these are called Computation Expressions) - Type-safety without too many annotations (global type-inference) - Mainstream ecosystem of libraries (in this case .NET) - Compile to JavaScript
- KurtMueller 5y agoUnits of measure is also very cool!
- enricosada 5y agoFor me is that pratically every time, if compile, it works. It's really easy to express a domain (with discriminated union and type) and the defaults (immutability, option, removal of boilerplate, high order function to manipulate data, structural comparison not reference) allow me to write correct code, who is readable without too much friction. Support a repl as first class, so that works too if you like repl driven development Community is also nice
- Smaug123 5y agoIt's just really pragmatic about the upsides of functional programming. It describes itself as "functional-first", but isn't afraid to fall back on OOP in situations where OOP really does model the situation better. In my mind, it's taken the easiest 80% of the features of a true functional language, but then picked a pragmatic point at which to stop; the result is a language which is easy to learn and also makes it easy to use "most" of the good things you want from a functional language.
- brightball 5y agoI believe it's the functional language option on top of .NET. From what I understand, it's a pretty well designed one too. I don't work in the .NET ecosystem, but I know if came up a lot when I was getting into Erlang/Elixir.
- bob1029 5y agoIf you want to dabble in functional, C# is actually a compelling option now. Switch expressions and LINQ can take you a long way. I strongly believe that functional programming is not a good fit for 100% of software architecture. The best is some sort of hybrid. Generally, the closer you get to the business logic, the more functional you would want to be. The serializers, http servers, etc. are probably not worth the squeeze to force into a functional domain.
- Koshkin 5y agoSure - C# is the best functional language, while Haskell has already been the best imperative language for a while now [0]. [0] https://stackoverflow.com/questions/6622524/why-is-haskell-sometimes-referred-to-as-best-imperative-language https://stackoverflow.com/questions/6622524/why-is-haskell-s...
- GuuD 5y agoI would have to respectfully disagree with you on the serializers part here. For me, after decades of fighting with “magic” stuff, simplicity is the key feature. So, everything that is a simple map function in disguise I tend to stick with functional languages and approaches.
- _v7gu 5y agoI think serializers would be better off as railways, allowing you to combine small serializers while also collecting the errors so you end up with a conclusive outcome. Haskell's parser combinators are quite fun for example. Also I've only used node/elixir serverside, but aren't http servers just a huge pipeline? It fits quite well into functional programming.
- bob1029 5y ago> aren't http servers just a huge pipeline Absolutely. At a certain level of abstraction they can be viewed in this way. How do HTTP servers actually get packets to and from the machine? At some point you have to interact with the operating system. This is not a realm where functional programming is very feasible today.
- infogulch 5y agoThere was a recent thread about Algebraic Effects in OCaml [0]. Does F# have something similar? [0]: https://news.ycombinator.com/item?id=28838099 https://news.ycombinator.com/item?id=28838099
- Smaug123 5y agoNo. It has lightweight syntax ("computation expressions") you can use to sugar monads, but no effects system.
- xvilka 5y agoIt lacks many things that OCaml has. On the other hands, units support is awesome, I wish there would have been more attention to that, and more popular in other languages as well.
- eatonphil 5y agoI've had good experiences running F# on Linux. I used it to build an API generator from database schemas [0]. Similar to Go you can get a single static binary you can copy anywhere. It's very convenient and you've got a massive number of .NET APIs to fall back on. The language is a little complex though. That you cannot call interface methods on an object implementing the interface without explicitly casting to the interface [1] is pretty weird. And getters/setters are a little complex. If you want an easy introduction to the ML family for educational/historic sake I'd always recommend Standard ML. But if you want a highly pragmatic, mature, strictly typed, compiled, cross-platform language F# is pretty compelling. [0] https://github.com/eatonphil/dbcore https://github.com/eatonphil/dbcore [1] https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/interfaces#calling-interface-methods https://docs.microsoft.com/en-us/dotnet/fsharp/language-refe...
- phillipcarter 5y agoThe language, in general, wants you to be explicit about what you're working with. So implicit access to interface members isn't a thing, you need to say that "x is this interface type" or cast. In F# 6 things are changing a bit, and may possibly change in the future. There are various classes of cases where the type information is known, but the compiler still required you to explicitly cast things to be happy. That's no longer case. This link[0] has 3 examples that don't compile with F# 5 but will compile with F# 6. [0] https://sharplab.io/#v2:DYLgZgzgNALiBOBXAdgHwPToAQFMAeAhgLYAOwOWAjALABQMAniRQIJYC8WAlsjDvGAIBjCjmQATOo2ZYAQgAoAlB269+gkVhZSmFAMJKVPPgOGs6dcjCxgshkFqO2YSCjAAWYuYZzAI+pQtaTFxCUnIsACZLHGsCLAdjLH8ARxUAbUoAbiicgGYAXSwgkPxiMgo8nRkWQ04hYAIICFwJaooFZU4eT3gua1rFGOswSLs8BzYAexIYLinkLrsh2mG7cQIYAkmsGbmFpYBlKaIKeU6V0btj07sLlbogA== https://sharplab.io/#v2:DYLgZgzgNALiBOBXAdgHwPToAQFMAeAhgLYA...
- Dayshine 5y agoImplicit upcast? That's amazing, I feel like that's going to help a lot with many branched functions.
- phillipcarter 5y ago
- JayGuerette 5y agoHis claimed inspiration, Hillel Wayne’s post “Why Python is my Favorite Language”, is a piece of fluff that basically says "I only like the things I already know". I was so uninspired, I couldn't read further.
- loic-sharma 5y agoYou fault an article for being superficial while yourself only giving a superficial read? I hope you see the irony and reconsider.
- StreamBright 5y agoF# has become my default goto language. It is absolutely amazing to create cloud services in it an I have a small ETL tool as well. I would not trade it for anything else.
- AtNightWeCode 5y agoIn my area there was a huge push for functional programming and F# some years ago. A long time ago since I heard anybody working with F#. Clojure is somewhat popular though in fintech. Functional programming is something I think one should learn cause the concepts are useful in other programming languages too. Over time what is useful in functional programming languages will be available in other languages. In fact, a lot already is. Functional programming is not an USP in my world. When I started with C#, code bases were full of GoF patterns, if and switch statements were banned, there were hierarchies of inheritance, there were states spread out and encapsulated everywhere, static functions were banned. Today, code bases are mostly stateless except for things that needs to be reused, there are pure functions everywhere, inheritance is mostly used in libraries and where interfaces can’t be used (yet), switch is ok and pattern matching is around the corner in several languages. More unpopular opinions. Immutability is overrated. In some programming styles, in some old languages there was a high risk of changing something by accident. Typical cause people did not know if they were working on a reference or a copy. Also, it was common to change fields on purpose. This problem does not really exist in a lot of programming languages today. But I do wonder if Go coders code benefit from some more immutability. I think the future of F# looks very dark but the functional style of programming will for sure have its place. What could change this is if F# really excels in some area like Go have done.
- DeathArrow 5y agoAfter null, the worst calamities that hit the software world are Uncle Bob's principles and GoF patterns. I mean what is more exciting than having to deal with FactoryFactoryFactory and AbsteactFactoryVisitorBuilderProxy written by others? Having forced OOP is bad enough by itself but people found ways to make software development even worse.
- jgwil2 5y agoLink to What I wish I knew when learning Haskell is broken because it has https. The correct link is http://dev.stephendiehl.com/hask/ http://dev.stephendiehl.com/hask/ in case anyone was looking for it.
- barrenko 5y agoWhen I learn Haskell, I'll be lot closer to God.
- DeathArrow 5y agoGod uses assembly.
- psd1 5y agoMolecular biology is implemented in perl.
- steve76 5y ago> Scott Wlaschin’s fsharp for fun and profit is one of the best functional programming resources I know across all functional programming languages. Hey! Someone else saw this. Very underrated resource. Also Professor Frisby's Mostly Adequate Guide to Functional Programming needs more attention too. Things I would add: 1. Start off with what types you need, not functions. Creating your types like the tools you need to do the job. Then build combinators. Convert one complex type to a primitive. Then a primitive to your type. 2. Once you have your types, it's not that difficult to make them functional. You just make methods for "of", or "chain", or "map", or "ap". Now you have monadic and applicative interface. 3. The functional part is just like when a shell drops to a program's prompt, like >ftp and >mysql. You setup a series of commands like that, with Either or Task or Fold. Provide input, prepare a list of commands, and then run them when everything is valid and ready. 4. Bundle size is a problem for web. Until tech improves and bandwidth prices lower, 100 KB on a high volume website is a problem. Nothing wrong with taking a proven solution, like wordpress, and caching it. 5. Property based testing is for under the hood, your types and combinators. It's not something you do with Cypress or units. All that input is type unknown, and needs validation before going to what's coverage under property based testing. 6. One fault that always occurs is trying to use Runtime encoding to build some extensible modular program. Don't do that. Types are for build. Validation is for runtime. If it doesn't validate, show a user a message. Don't try to build some hot swappable modular program, where types are read from input. If they want to program the computer, they can install the IDE.
- rcarmo 5y agoPretty much on point. I've been building a .NET, bootstrapped webapp (i.e., no Razor, no "cargo culting" so I can actually understand things from the ground up) piecemeal, every other weekend, in both C# and F#, and, like Java before it, _understanding the ecosystem and libraries_ is critical. I can read OCaml and dabbled in it, but that doesn't help me write substantially better .NET because I will be iterating over lists or graphs in a different way, handling IO (and sockets) differently, etc. But I can see how someone conversant with C# and the .NET ecosystem would really like F# since the barrier to entry is substantially lowered, and the code is just so much nicer and tidier. Shame there isn't a proper AOT-compiled LISP for .NET (no, Clojure doesn't count, I never managed to get the .NET version to work for me).
- chalst 5y agoThe main thing I found strange about F# was that, having prior familiarity with Ocaml and SML/NJ, was that what F# calls modules are completely unlike the module system of any other ML-inspired language, being instead an adaption of C# classes to serve F#'s namespacing needs. Since the module system is of similar importance to code reuse to Haskell's typeclasses,the relative deficiencies of F#'s module system hurt.
- vasergen 5y agoI wish I have Elixir with types like in F#
- Rapzid 5y agoI wish F# had a project comparable to Phoenix to boost its visibility.
- DeathArrow 5y agoIt has Giraffe, SAFE stack, Fable, Bolero.
- gorgoiler 5y agoWhat’s the best way to play with F# that feels natural for a Python programmer? I really like having my screen split down the middle (tmux), with code on the left (“vim code/“) and program output on the right (“watch-exec code/ — python -mcode”). Every time I change a file in code/, watch-exec runs the program again. Doing this with dotnet run seems to take a full 2 to 4 seconds to run though, which seems pretty heavyweight. It’s obviously not the best way to interactively edit a file of code. What is?
- 2mol 5y agoYes! Those couple of seconds wait-time are a big bummer for that style of fast-feedback coding (for which there is the built-in `dotnet watch run` by the way). Made me sad when I was playing around with generative art, where you would really want to see the result of your changes in a split-second. You can check out ".NET Interactive Notebooks" in VSCode, that executes much faster, but it doesn't do this live watch.
- akra 5y agoYeah I think 'dotnet fsi {fileName}' with a script file works. Also Ionide with VS Code using Alt+Enter (similar to other language VS Code repl's) inside a *.fsx script file to run the highlighted code in a F# REPL. F# Interactive has doco online as well that isn't that long but covers most things (single commands, script files, loading packages, etc).
- dunefox 5y agoThe obvious solution is not to compile your project with every change. See F# interactive: https://www.jetbrains.com/help/rider/FSharp_interactive.html https://www.jetbrains.com/help/rider/FSharp_interactive.html