Live data from Hacker News

Why F#?

batsov.com

111–120 of 424 posts

Re: Why F#?

#111
> Trivia: F# is the language that made the pipeline operator (|>) popular.

I’m not a dabbler in exotic languages, so this definition of “popular” was puzzling. I’ve literally never seen that operator before. Maybe I need to get out more.

Re: Why F#?

#113
post #29

I did try F#, but I was new to .NET ecosystem. For 1 "hello world" I was quite surprised by how many project files and boilerplate was generated by .NET, which put me off. I am all for FP, immutable, and modern languages. But then where are the jobs and which companies care if you write good code? Now everyone wants languages which are easy to use with AI, while reducing workforce and "increased productivity". I have…

I like F#'s syntax when all you're doing is pure logic. But when you have to interface with any IO like a database or REST call or something, you have to abandon the elegance of ML syntax and use these ugly computation blocks. In C# you can do something like this: var post = await _postService.getById(id); in F# the equivalent is basically let getPostById id = async { let! post = blogPostService.getPostById id return…

`var post = await _postService.getById(id);`

the F# equivalent is

`let! post = _postService.getById id`

Re: Why F#?

#114
post #29

I did try F#, but I was new to .NET ecosystem. For 1 "hello world" I was quite surprised by how many project files and boilerplate was generated by .NET, which put me off. I am all for FP, immutable, and modern languages. But then where are the jobs and which companies care if you write good code? Now everyone wants languages which are easy to use with AI, while reducing workforce and "increased productivity". I have…

>" I was quite surprised by how many project files and boilerplate was generated by .NET, which put me off.

With which language are you comparing with?

Because there's afaik csproj and maybe .sln

and both of them are let's be frank - foundational for almost all projects that arent just hello world.

Otherwise you end up with some cmakes or something similar that want to achieve something similar

Re: Why F#?

#115
post #22

Earlier quoted context omitted.

The funny thing is that you can write very similar code in C#, so maybe you don't need to switch which language you're using as a CLR frontend. using System.Linq; using System; var names = new string[] {"Peter", "Julia", "Xi" }; names.Select(name => $"Hello, {name}").ToList().ForEach(greeting => Console.WriteLine($"{greeting}! Enjoy your C#")); LINQ is such a good library that I miss it in other languages. The Java s…

Modern C# collection expressions make the definition of names closer to F#: string[] names = ["Peter", "Julia", "Xi"]; I know working on "natural type" of collections is something the C# team is working on, so it feels possible in the future that you'll be able to do this: var names = ["Peter", "Julia", "Xi"]; Which I think would then allow: ["Peter", "Julia", "Xi"].Select(name => $"Hello, {name}").ToList().ForEach(g…

I did try that initially and got

    (5,1): error CS9176: There is no target type for the collection expression.
.. which I took to mean that, because .Select is an extension method on IEnumerable, the engine was unable to infer whether the collection should be a list, array, or some other type of collection.

It seems reasonable to have it default to Array if it's ambiguous, maybe there's a downside I'm not aware of.

Re: Why F#?

#116

> Trivia: F# is the language that made the pipeline operator (|>) popular. I’m not a dabbler in exotic languages, so this definition of “popular” was puzzling. I’ve literally never seen that operator before. Maybe I need to get out more.

It exists in several similar languages such as elixir, and was even a proposal for ecmascript, but never really got traction.

Re: Why F#?

#117
F# is a very well-polished functional language. Think of it to Haskell as C# is to Java. No worries about space leaks or purely-academic syntax or monads (though you can get those if you need them). All with tight integration into one of the biggest, well-established ecosystem (CLI). It's managed by smart people who know how to keep it from derailing as it grows.

Re: Why F#?

#118

F# was for me the best functional language when I looked at rewriting a Ruby on Rails app. I wanted to go with a functional language, as it seems to better fit my thinking and reasoning, and I looked at Haskell, Ocaml, Scala, F#. Being a stranger to Microsoft technologies, F# was the least likely to be chosen, but easily became the first choice. Haskell's purity made it hard to adopt (for me), Ocaml's ecosystem is su…

Great story! Thanks for sharing it!

Re: Why F#?

#119

Earlier quoted context omitted.

I like F#'s syntax when all you're doing is pure logic. But when you have to interface with any IO like a database or REST call or something, you have to abandon the elegance of ML syntax and use these ugly computation blocks. In C# you can do something like this: var post = await _postService.getById(id); in F# the equivalent is basically let getPostById id = async { let! post = blogPostService.getPostById id return…

In C#, you can't use the await keyword in a non async method, so I find the argument short sighted.

If your code base is already using async await it's really not an issue.

Re: Why F#?

#120
post #33

Earlier quoted context omitted.

you are not supposed to do oop in f#

F# depends heavily on existing C# libraries and those are all OOP.

One way to look at it, but consuming OOP libraries doesn't turn code into OOP.

Also, FSharp.Core (which most F# code leans heavily on) is not OOP at all.

F# promotes object programming, doesn't proscribe mutability, encourages function and data approach.

It offers simple access to the different paradigms, with some opinionated choices (e.g. preventing leaning on OOP beyond an arbitrary stretch, like no "protected", only explicit interface implementation, etc.).

Post reply on HN