5 ms·
I've recently become interested in F# after I saw its use in a bunch of videos by Scott Walashin. I came across his talks, and subsequently his blog, as I'm get
by bern4444 6y ago
I've recently become interested in F# after I saw its use in a bunch of videos by Scott Walashin. I came across his talks, and subsequently his blog, as I'm getting more into functional programming and he has some awesome content.
I use Javascript/Typescript professionally and I really like both of them. F# though has a minimalism in its design that is very appealing. Code I write in F# feels a lot less cluttered as opposed to the same function in Javascript/Typescript. This minimalism seems to be part of the language design with some following specific examples.
- `let` is used to declare variables and functions.
- The last statement in a function is implicitly the return value.
- The type safety/mechanism is great and seems to be extremely similar to Typescript's so its easy to pick up for me (I'm not sure which came first or if there's a relationship but it certainly wouldn't surprise me).
This along with some classic functional ideas that are built in like immutability by default, automatic currying of functions etc all allow for a language that seems be made to get out of the way. That's a very compelling idea for a language design to me that I previously haven't seen.
Because functions and variables are both declared with let, perceiving functions as data kind of finally clicked for me since I first heard that concept 3 or so years ago. Another feature was to not require a semicolon as a line terminator and instead use it for another meaning as a separator. While JS doesn't require semicolons at the end of a line, its reserved for that purpose.
Overall, I find F# to be a refreshing language (from javascript, python, java and even others like Rust or Go but I haven't used those as much so don't want to make bigger claims) and I'm glad to see a post like this on HN almost like validation of a community behind the language. I'd be curious to get a feel for some companies that actively use it as well.
I also love that there's a compiler for F# to Javascript so I can use it to build front end code as I learn the language. Its pretty incredible we can do cross compilation of high level languages like this and with others like Rust and Go to wasm etc
Edit: formatting of bullet points
- logicprog 6y agoWow this is a great comment about a new-to-FP viewpoint on F#. I came to it after I'd already experimented with Haskell and OCaml, used Rust a lot, and been programming with Lisps for years - and I was really impressed with it nevertheless! I really love the ML-family type systems. They're really great aides to programming, and makes planning really nice. F# has that, plus that usability from C# and TS. It's also, like you said, got a really beautiful syntax IMHO. I keep coming back to Rust though, because Rust is more general purpose, more performant, and applies better to the stuff I like to work on for my hobby projects. I'd love to use F# more but can't find a reason to at the moment. TypeScript, Python and Rust have become my comfort languages, but I like Rust the best, because it's got a lot of really nice features from ML languages and a powerful and safe type system.
- bern4444 6y agoRust is actually the one other language I'm interested in learning now and is on my list. I have a feeling I'll be in a similar mindset to you once I learn and get some experience with it. I'm interested to compare its syntax to F# as well since to me the F# syntax and design is what I find most compelling. More broadly there seems to be a big push for updated (perhaps even modern) versions of established languages and I think this is an incredible development to witness. Rust, Go, Typescript, Scala, Kotlin are all the rage and seem to replace C/C++, javascript, and java. Others might exist for either side as well, this is just off the top of my head. From what I see and read as well functional programming seems to be a lot more popular and a lot of these languages are either built for it or with a good base of support for it. It'd be really interesting to have some hard data to know if this is accurate or just my perception. My only other exposure to functional programming was an undergrad class required for a CS major (thank gosh it was a requirement too). It used Scheme for the language and Structure and Interpretation of Computer programs for the text book[1]. Looking back, this was the most useful class I took and the ideas have stuck and continue to inform me today. Its the one text book I've gone back to on occasion just to take a look and I've found some versions of it for JS and F# even on github which I use to help learn the language or review the concepts in languages I'm more familiar with. [1] https://mitpress.mit.edu/sites/default/files/sicp/full-text/book/book.html https://mitpress.mit.edu/sites/default/files/sicp/full-text/...
- gavinray 6y agoF# has the nicest syntax of any language IMO, it's a shame it's not got a larger mindshare.
- bern4444 6y agoHigh praise and interesting to hear this as well from someone else. I feel like I'm on the right track with my analysis in my main comment. I saw in a different HN post a few weeks ago that jet.com heavily used F# but obviously that's no more. If a company were using F# and I were looking to switch and all the other stuff was a good match, the language choice would be a big pull for me. While I use and am learning F# for a side project, there's no substitute for working with one professionally and shipping production code with it. I wish it'd be possible to convince my engineering group to use it.
- xvilka 6y agoOCaml also has a compiler to JavaScript - BuckleScript[1]. There is also js_of_ocaml[2], jsoo in short. Though I personally hope they will go with the WebAssembly route[3] and support it in the mainstream compiler out of the box. [1] https://bucklescript.github.io/ https://bucklescript.github.io/ [2] https://ocsigen.org/js_of_ocaml/3.6.0/manual/overview https://ocsigen.org/js_of_ocaml/3.6.0/manual/overview [3] https://discuss.ocaml.org/t/state-of-ocaml-and-web-assembly/2725 https://discuss.ocaml.org/t/state-of-ocaml-and-web-assembly/...
- jen20 6y agoScott's talks about F# are exceptional, and quite compelling for "line of business" developers (as opposed to language enthusiasts) - something functional programming advocacy often misses in my opinion. This is also something that his site (https://fsharpforfunandprofit.com https://fsharpforfunandprofit.com) does a good job of. On a slight tangent, you might enjoy the slides from Scott on a different topic - model checking with TLA+ - from NDC Oslo this week: https://www.slideshare.net/ScottWlaschin/tla-for-programmers-235339832 https://www.slideshare.net/ScottWlaschin/tla-for-programmers...
- bern4444 6y agoOh that's awesome. I first came across TLA+ (probably also through HN) about 6 months ago and recognized Leslie Lamport's name. The concept was very interesting but I had trouble getting to a good enough understanding of TLA+ to be able to use it. I'll look to see if I can find the associated NDC talk on youtube but his slides are also great. Thanks for sharing. He does an incredible job conveying the ideas and intuition behind a lot of the terms and concepts for a given subject.
- jen20 6y agoI don't think the talks have been published yet (they were only given ~2-3 days ago), but agreed on the slides being useful!
- jolux 6y agore: relationship to TypeScript, I'm interested in which parts seem similar between the two to you. TypeScript is primarily structurally typed while F# is primarily nominal.
- bern4444 6y agoSure thing, I'm still pretty new at F# but have a good handle on Typescript since I get to use it at work. The three main things I find similar are the syntax, ability to compose new types from other types, and the ability to limit types to certain options. Both support | as an OR and support an AND operation. F# does a bit more allowing the product of types though. Syntax Example: Typescript --------------- type Check = { amount: number; account: number; ... } F# -------------- type Check = { account: int; amount: int } I think I need to become a bit more familiar though with F# to understand the differences better. I hadn't yet heard the term nominal to describe a type system before so I'll look into it further. Perhaps I'm focusing more on the syntax than is warranted... Completely separately, how does one properly format on HN? Is it possible? Is there a doc somewhere? I'm fairly new to commenting...
- jolux 6y agoFormatting is rudimentary but it exists: https://news.ycombinator.com/formatdoc https://news.ycombinator.com/formatdoc Your example is actually a really good one for discussing these differences, and the syntax is indeed similar. That TypeScript code is introducing a "type alias," which is a special name for another type, rather than a new type of itself. (https://www.typescriptlang.org/docs/handbook/advanced-types.html#type-aliases https://www.typescriptlang.org/docs/handbook/advanced-types....) This is a concept that F# does not have, because F# doesn't support structural typing. In TypeScript, you could just as well specify that a function returns { amount: number; account: number; } directly, and it would be equally compatible with anything expecting a "Check," because Check is just a shorthand for that object type. I can't easily declare that a function accepts { account: int; amount: int; } in F#, I have to declare that it accepts "Check." That is the main difference between TS and F# here, and incidentally also the most basic difference between structural and nominal type systems. I'm not sure why the syntax is similar though, F#'s is based on OCaml's record syntax while TypeScript's is really just a JavaScript object literal but with semicolons instead of commas. I believe it supports commas too. It may be genuine coincidence, or the designers of TS may know of the ML family, which is highly influential among language designers and implementers.
- sasmithjr 6y agoYou can use F# in WebAssembly, too, via Bolero[0]. [0] https://fsbolero.io/ https://fsbolero.io/
- kingdomcome50 6y agoThere is a lot to like about F#, but I honestly prefer Typescript. I feel like it really has hit the sweet spot between FP and OOP. And while I do tend to prefer the more terse ML syntax of F#, Typescript is pretty close and, frankly, offers a more ergonomic experience in your editor (F# syntax highlighting in every editor I have used is woefully underwhelming). Add to the above the structural typing vs nominal and Typescript really does offer an immensely rich and flexible paradigm. The only feature I'd really like to see better support for in Typescript is currying/partial application These can be approximated in TS using it's incredibly powerful type system (dependent types using "extends" combined with inference using "infer"), but newer versions will throw an exception when the compiler sees an infinitely recursive type.