Live data from Hacker News

A whirlwind tour of object-oriented code in F# (2012)

fsharpforfunandprofit.com

61–70 of 130 posts

Re: A whirlwind tour of object-oriented code in F# (2012)

#61
post #5

While there's nothing you can do in C# that cannot be done in F#, the reverse is not true. The biggest thing that comes to mind is to influence the direction of the other language (C#). I've heard it said many times that if you want to see what features will be in C# in the future, look at F#. Too many features to cite (though Linq is the biggest that comes to mind) were in production use in F# long before they arriv…

There's actually a couple of minor things (like covariance). I was surprised to learn F# doesn't support creating sealed methods on classes the other week when I was extending some OO code.

Thankfully F# and C# mix so well together I could've written a quick C# project to do it if needed, but I didn't want to break up my F# project into two + some C# glue

In the vast majority of cases though what you said is true. Discriminated unions, records, computation expressions, and type providers are total game changers

Re: A whirlwind tour of object-oriented code in F# (2012)

#62

Earlier quoted context omitted.

Scala is probably the most pragmatic functional programming language to get a job in. It's on the JVM and you can use all the Java libraries, and it also lets you fall back to an imperative style if you need to.

That sounds exactly the same as F# (except there might be more jobs in scala). F# is on .NET CLR and you can use all the .NET libraries, and it lets you fall back to an imperative style if you need to!

> you can use all the .NET libraries

did you try it?

Hint: there is a lot of things required before F# could use latest WinUI or WPF

Re: A whirlwind tour of object-oriented code in F# (2012)

#63
post #44

Earlier quoted context omitted.

That sounds exactly the same as F# (except there might be more jobs in scala). F# is on .NET CLR and you can use all the .NET libraries, and it lets you fall back to an imperative style if you need to!

Try to use EF, WCF, UWP, WPF from F#.

EF isn't really needed with Dapper and the available SQL type providers. Even still it's totally naturally to have a C# project holding the base EF stuff which you reference from your F# projects

Re: A whirlwind tour of object-oriented code in F# (2012)

#64
post #50

I think several interesting points were brought up in this thread regarding the assumption of functional aspects presented in F# by C#. LINQ being the most popular example. I am currently lead to believe that a purely functional application development domain is potentially an overreach of theory in terms of building things that can interact with the real world in very complex and 'functionally-leaky' ways. My biased…

On the contrary, you have a huge advantage to interface with the dirty world using F# thanks to exhaustive pattern matching and you can make everything type safe to render invalid state unrepresentable.

Re: A whirlwind tour of object-oriented code in F# (2012)

#65

Years ago I was working a miserable job writing boilerplate template code where I had to sub in variables based on certain conditions, it was using a very bland language to look up data from our database and format the output. I wasn't allowed to download any software onto my work computer despite having a technical background. So what I did instead to make my life easier was write F# to create a kind of DSL and crea…

What do you do where you are using Racket most of the time?

Re: A whirlwind tour of object-oriented code in F# (2012)

#66
post #4

F# is a joy to use. After a certain time, many C# developers find themselves writing in a functional style. F# makes this the default, but lets you continue using all of your existing code. Better yet, Linux and macOS support via .Net Core is excellent. F# on .Net Core is now a powerful alternative to Node.js.

C# for the most part does a decent job with Functional Programming, but it still leans very heavily towards statements instead of expressions. Even the newly introduced pattern patching (a common FP idiom) ended being a switch statement - perplexing decision because expressions are so central to good FP code. And if you were in imperative land, you didn't really need pattern matching so much in the first place; most developers will be fine writing if conditions.

I hope they fix these warts. It can soon be a good alternative to Go for real native applications.

Re: A whirlwind tour of object-oriented code in F# (2012)

#67
post #53
post #42

Earlier quoted context omitted.

OOP is not idiomatic F#. It is mostly for interop with C#.

I would not say that, sometimes it's quite powerful to combine these paradigms. I think they would not design a language for CLR only to force them to create a huge interop subsystem. You are right, however, that OOP should not be the default way to write things in F#.

I definitely appreciate being able to drop into an OOP style when I find it's necessary. In a talk Don Syme (F#'s original designer) goes into aspects of OO he enjoys, those understands the usefulness of, and those he does not enjoy. I believe it was F# Code I Love, which gives some good insight into the thinking behind the language.

Re: A whirlwind tour of object-oriented code in F# (2012)

#68
post #66
post #4

F# is a joy to use. After a certain time, many C# developers find themselves writing in a functional style. F# makes this the default, but lets you continue using all of your existing code. Better yet, Linux and macOS support via .Net Core is excellent. F# on .Net Core is now a powerful alternative to Node.js.

C# for the most part does a decent job with Functional Programming, but it still leans very heavily towards statements instead of expressions. Even the newly introduced pattern patching (a common FP idiom) ended being a switch statement - perplexing decision because expressions are so central to good FP code. And if you were in imperative land, you didn't really need pattern matching so much in the first place; most…

C# 8.0 will have a switch expression: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csh....

Re: A whirlwind tour of object-oriented code in F# (2012)

#69
post #22

Years ago I was working a miserable job writing boilerplate template code where I had to sub in variables based on certain conditions, it was using a very bland language to look up data from our database and format the output. I wasn't allowed to download any software onto my work computer despite having a technical background. So what I did instead to make my life easier was write F# to create a kind of DSL and crea…

Reads like an opening of a dystopian novel!

Heh. I was doing manual deployments because of dumb bank policies so after a lot of maneuvering I used Powershell and plink.exe to write a small, dumb version of Python's Fabric to be able to automate deployments.

I was writing Powershell in Vim while trying to keep my skunkworks project out of sight because of crappy management policies.

Sometimes you gotta make lemonade...

Post reply on HN