Live data from Hacker News

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

fsharpforfunandprofit.com

71–80 of 130 posts

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

#71
post #15

I used to be a big Haskell programmer. While I still love the language, I've really come around to the idea that strictly evaluated functional languages like F# or OCaml are the best for programming in. You get the nice functional features but don't have the straightjacket of laziness forcing you into certain design decisions. It's really nice sometimes to be able to mix in impure, side effectful code without having…

I use F# daily, and to get around this limitation I use hacky custom code generation an F# script (fsx) to generated specific types. Additionally, on cases where you’re not specifying the data of the type itself, you can use static type constraints on members. This doesn’t give you a default implementation like Haskell but you can always provide one as a function. Btw the monadic threading is still very useful, espec…

Oh, for sure I still love monads. I miss Haskell's do syntax in every other language. I think it's a great design pattern that starts popping up constantly once you know where to look. My objection is being forced to use monads due to the language's lazy by default semantics. You get this problem with haskell where the IO monad eventually just pollutes a huge chunk of your code because you can't safely sequence side effects without it. Sometimes I just wanted an escape hatch that would let me do side effects that I knew to be safe/harmless. Haskell has unsafePerformIO but it truly is unsafe because you can't guarantee the execution order of your side effects, which makes it useless as an escape hatch for a lot of purposes.

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

#73
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…

> While there's nothing you can do in C# that cannot be done in F#

Really? When did F# start supporting pointers?

> to influence the direction of the other language (C#)

Lately, it seems it's the other way around: C# is introducing features like Span or default interface members and F# is (quickly) catching up.

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

#74
post #48

Earlier quoted context omitted.

C# has most of the same pattern matching functionality at this point

There's no compiler warning for incomplete matches, and without discriminated unions it's pretty verbose to write pattern-match friendly types C# has support for most F# features, they're just often awkward to use

You can get a pretty reasonable facsimile using some libraries I made:

Discriminated unions: https://github.com/mcintyre321/OneOf and One line value objects: https://github.com/mcintyre321/ValueOf

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

#75

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?

For now it's a lot of database ETL and network services at my new job. If I'm not using Python, there's a good chance I'm prototyping something in Racket.

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

#76

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!

> 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

I wouldn't call those libraries. If you have something that's actually just a library, using it from F# should not be a problem.

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

#77

Earlier quoted context omitted.

There's no compiler warning for incomplete matches, and without discriminated unions it's pretty verbose to write pattern-match friendly types C# has support for most F# features, they're just often awkward to use

You can get a pretty reasonable facsimile using some libraries I made: Discriminated unions: https://github.com/mcintyre321/OneOf and One line value objects: https://github.com/mcintyre321/ValueOf

I'm constantly impressed by ways people manage to extend C# like this. I'll have to try this out :)

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

#78

Earlier quoted context omitted.

C# was usable in VS Code even 3 years ago

How is it these days? Is it “usable” or actually something you want to and enjoy using? Will I be left wanting Visual Studio? I mean I really enjoy IntelliJ, it makes programming Java like slicing butter. But I do want to try F#, people talk so highly of it.

> I really enjoy IntelliJ, it makes programming Java like slicing butter.

In that case, I think you want an actual IDE and VS Code is not that. The options you have for .Net are Visual Studio and Rider (which is from the same company as IntelliJ and shares a lot of code with it).

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

#79
post #68
post #66

Earlier quoted context omitted.

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... .

As C# gradually becomes F#, I have to wonder, why not just use F#?

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

#80
post #55
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.

> After a certain time, many C# developers find themselves writing in a functional style If you can't move to F# or find its tooling abysmal and slow then I have a library [1] that makes the inertia flow positively in the functional direction in C# https://github.com/louthy/language-ext/

After learning f# I had to go back to c#. You library made it bearable. Also the reader.md and some of your more hidden articles are amazing. Thank you, and the other contributors so much, amazing work.

My current strategy is to hook my colleges in with languag ext until they move to f# themselves.

Post reply on HN