News for hackers. Stuff that matters.
Re:A whirlwind tour of object-oriented code in F# (2012) by danite on Wednesday May 22, 2019 @10:12AM (#19981368)
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 to thread it through a monad. The OCaml family feels like a nice blend of good sound functional features with enough escape hatches to be productive in real world programs that might occasionally need arrays or mutable state or IO. Laziness by default also makes things like debugging or reasoning about performance frustratingly difficult. I do miss Haskell's typeclasses in these languages, though. My ideal language is basically Ocaml/F# but with Haskell's syntax and typeclasses.
Re:A whirlwind tour of object-oriented code in F# (2012) by jlturner on Wednesday May 22, 2019 @11:08AM (#19981988)
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, especially when mixing impure code and mutation (when appropriate). The async and result monads, in F# computation expression form, are particularly useful.

For a good example of async + impure code, check out MailboxProcessor, which is part of the standard F# lib. Works similar to CSP/goroutine + channels/actor models; makes parallelized concurrency and message passing easy. You can also make pure mailboxes easily by recursively passing data forward, but sometimes you don’t want to for memory / gc & alloc reasons.

Re:A whirlwind tour of object-oriented code in F# (2012) by danite on Wednesday May 22, 2019 @11:34AM (#19982294)
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) by dean177 on Wednesday May 22, 2019 @02:38PM (#19984119)
Ocaml is getting something similar to ‘do’ syntax very soon (but for applicatives too!):

http://jobjo.github.io//2019/04/24/ocaml-has-some-new-shiny-...

Re:A whirlwind tour of object-oriented code in F# (2012) by adgasf on Wednesday May 22, 2019 @10:34AM (#19981597)
Re:A whirlwind tour of object-oriented code in F# (2012) by k_cieslak on Wednesday May 22, 2019 @02:33PM (#19984076)
Hopefully not :-)
Re:A whirlwind tour of object-oriented code in F# (2012) by willtim on Thursday May 23, 2019 @02:41AM (#19989121)
It's easy to forgot the benefits of laziness: http://augustss.blogspot.com/2011/05/more-points-for-lazy-ev...

Laziness is a good default for declarative programming. Nix from NixOS is an example of a recent lazy language and benefits greatly from it.

Even in strict languages, lazy behaviour is often added, for example iterators and streams. Mixing effects and mutation with such constructs is also problematic.

Re:A whirlwind tour of object-oriented code in F# (2012) by PyroLagus on Wednesday May 22, 2019 @12:21PM (#19982776)
I'm not saying it's a replacement for either F# or OCaml, and I've only glanced at it, but F*[1] looks pretty neat. It's higher-level than F# (a lot) and has a syntax more similar to Haskell's. You can even extract programs in F# and OCaml.

[1] https://www.fstar-lang.org/

Re:A whirlwind tour of object-oriented code in F# (2012) by pavelbr on Wednesday May 22, 2019 @12:44PM (#19982961)
My experience with F* is several unsuccessful hours of trying to compile hello world thanks to a complete lack of instructions for configuration and installation.

I hope it's gotten better.

Re:A whirlwind tour of object-oriented code in F# (2012) by new4thaccount on Wednesday May 22, 2019 @06:38PM (#19986323)
F* or F#? They are very different.