6 ms·
> It's a little known fact but the kind of FP programming we do in Scala tends to be more pure than what happens in OCaml, F#, Erlang, Clojure and others. I ha
by willtim 7y ago
> It's a little known fact but the kind of FP programming we do in Scala tends to be more pure than what happens in OCaml, F#, Erlang, Clojure and others.
I have only dabbled in Scala, but IMHO it's more suited as an OCaml with first-class modules. Why not use Haskell, if you don't need the JVM?
- bad_user 7y agoCompared with OCaml, Scala can express type classes and has higher-kinded types. Many abstractions that are easy to express in Scala are in fact hard to express in OCaml. For-comprehensions are worse than Haskell's do-notation or compared with F#'s computation expressions, but the list ends there. In practice they work well and at least Scala has monadic for-comprehensions. How many other languages can claim that? As for performance, I encourage you to take a look at the state of the art. Working with our IO Monads has better performance than many abstractions that people now take for granted, like most Future/Promise implementations. I build systems that are super stressed by incoming traffic and Scala's performance is awesome. Worse than bare metal Java of course, but when you compare it with high level Java frameworks or with Python/Ruby/Javascript/what have you, you'd actually be surprised by how better Scala FP is ;-) As for Haskell, I like the language, but it's super fragmented, everyone has its own Prelude and favorite language extensions, extensions that are sometimes in conflict with other extensions and the tooling is a mess. Also laziness is cool, but performance gets hard to predict. We have the same problem in Scala when we are using lazy abstractions actually, the difference being that Scala is opt-in instead of opt-out. With Scala, even if you're targeting JS instead of the JVM, you still use the same tools. And I even like the language better. Scala 3 will fix many annoyances I have, including adding untagged unions and GADTs that are based on ADTs, in other words nicer than Haskell. PureScript I would like though, as it fixes some of Haskell's problems, maybe one day it won't be limited to JS.
- willtim 7y agoThanks for the detailed reply!
- dm3 7y ago> As for Haskell, I like the language, but it's super fragmented, everyone has its own Prelude and favorite language extensions, extensions that are sometimes in conflict with other extensions and the tooling is a mess. Also laziness is cool, but performance gets hard to predict. We have the same problem in Scala when we are using lazy abstractions actually, the difference being that Scala is opt-in instead of opt-out. Not an expert in Haskell, nor Scala - only dabbling. However, the above could be repeated verbatim after replacing Haskell with Scala, couldn't it? You can write Java++, Haskell-- or any combination in between. Use one of the several FP stacks or build tools. I think both Scala, Haskell and C++ can compete for the name of the most complicated, fragmented and diverse language and ecosystem in existence.
- bad_user 7y agoI think people are too quick to judge languages. If I tell you that Haskell has a fragmentation problem, I feel good about telling you that because I actually have experience with it. However Haskell is still a language that I'd pick over Java, Go, JavaScript or any of the mainstream languages for that matter and I'd be willing to put my reputation on the line for that choice. I also worked with C++. To see people compare Scala and Haskell with C++, kind of rubs me the wrong way. And unfortunately such opinions stay on the Internet forever, are picked up by beginners and repeated verbatim. So no, there's a huge difference between Scala, Haskell and C++. For one the former wouldn't lead to stupid and disastrous bugs like Heartbleed, whereas C++ can and routinely does. By comparison when well typed Scala or Haskell programs compile, the defect rate tends to be really low. I'm seriously thinking about starting a course in how badly and easily you can fuck up in C/C++, for people that make unfair comparissons with them, making life hard for their managers :-) Also just to get this out of the way... the problem in Scala are actually the Java refugees going gung-ho on OOP. And the FP people, because they tend to be more experienced, are the ones cleaning up the mess. And I like that. You know why? Because Scala makes it possible to introduce FP gradually, without an organization wide commitment. In the company I'm working for, a language like Haskell would never fly, but Scala does. Also in case you haven't noticed, FP is spreading. - in Typescript/JS you have fantasy-land and fp-js - in Kotlin you have Arrow The difference is that you don't get the nice type system to support those abstractions well, so you also get the weird HKT and type class encodings to go with it. Although in fairness the Arrow guys are working on compiler plugins for better supporting type classes and the HKT encoding that they use. So if you're conservative about adopting FP, language choice will not really protect you ;-)
- mark_l_watson 7y agore: “ As for Haskell, I like the language, but it's super fragmented, everyone has its own Prelude and favorite language extensions....” I really like Haskell, but this aspect of the use of Haskell also bothers me. I use a small subset of Haskell and language extensions, a small subset that I am happy and productive with, but it takes me a lot of effort to understand other people’s code.
- tome 7y ago> extensions that are sometimes in conflict with other extensions Could you name two widely-used extensions that conflict with each other in a non-trivial way? I've used Haskell for several years and I've never come across any.
- weberc2 7y agoRegarding purescript, I thought I saw a post on the other day that said it now has C++ and Go backends.
- dllthomas 7y ago> everyone has its own Prelude In my Haskell experience (including some professional experience) this isn't the case very often at all (maybe not even as often as it should be). (Which is not to say that there aren't some problems with fragmentation elsewhere in Haskell's ecosystem)