by atemerev · 10y ago · 0 comments
I know, many people are happy to go full throttle on Cats/Scalaz/whatever, but there's already Haskell for that. Official Scala documentation never even mentions the word "monad" (not even once!), and I think this is a good thing.
> Official Scala documentation never even mentions the word "monad" (not even once!), and I think this is a good thing
Actually that's a huge mistake because Scala is amongst the few languages that can express the Monad as a type. In most mainstream languages monads aren't explained because those languages lack the capacity for doing it. It's no wonder that people have a hard time understanding monads without a type to look at, as that would be like describing an elephant to a blind man. Do you think you understand Iterable because of its name? No, you understand it because you've seen its interface clearly described and then you used it and learned to appreciate it.
And really, the strangest things happens when you don't talk about it. You still have for comprehensions, but surprise, they don't behave like in Python, "yield" is again overloaded, having nothing to do with Python's yield or Ruby's yield, and people stumble for no good reason, because it is hard to connect what seems like syntactic sugar over iterators to an expansion using map and flatMap. Along with "computation expressions" from F# or other bullshit naming meant to not scare away the most sensitive of us, the big problem that happens is that people get confused and don't even know what to search for. Search for monads and you'll find endless articles, tutorials, books, research. Search for comprehensions and you get shit.
This is basically anti-intellectualism, the same kind of attitude that made Trump popular and that encouraged Brexit. The same kind of attitude that made the Option type in Java violate the Functor laws, taking a concept and destroying its essence just because we're afraid of big words and the opinions of experts.
I agree that Monads deserve our time and attention. Unfortunately, search for monads and you'll get thousands of articles explaining what they are in incomprehensible terminology, along with language-specific type annotations, and devoid of any practical reasons to use them over their non-monadic control flow cousins in imperative languages.
They never seem to explain why you would ever need them, how they help in certain situations. Even worse, they don't tell you when they might actually be hazardous or code smell. They rarely even gloss over the challenges (like needing monad transformers if you want any sort of monadic composition), leaving you to figure that out for yourself when you start bashing your head against the walls.
For all their hard-to-google non-standard terminology, the Scala and F# communities have done a far better job than Haskell at explaining Monads in a way that actually makes people want to learn and use them. And once they have learned the concepts, the elitist sounding language doesn't sound quite so intimidating anymore.
For fucks sakes, nobody invents words like "monad" to sound elitist.
> its essence just because we're afraid of big words and the opinions of experts.
I think most of the distaste for terms like Monad, is a failure to communicate it's meaning to a lot of people, it reminds me a lot of Enterprise Java terminology with terms like factories, abstract/factories, Bean, ect, that provide just as much intuition into their own meanings from their names. And when you look up their meanings you get hit with even more obtuse terminology. Like for example a in a less formal discussion about programming, a term like "pure functions", can simply described as "stateless function" [1]. You don't need to automatically reach for the big words, when a more commonly understood word sufficiently communicates something. Unfortunately I'm not so sure there's such a word for monad however.
In the case of Elm, it has this approach to naming things with less formal names where it can use something more comprehensible. The author of the Elm language mentions this in a talk of his [1] (just scroll to the section on being direct).
I really see this more as a communication issue, not everyone in software has a duel degree in abstract mathematics & computer science, let alone a degree.
[1]: http://www.elmbark.com/2016/03/16/mainstream-elm-user-focuse...
When it comes to Monad et al I'm reminded of this talk by Gilad Bracha. He points out that the function names and type names that stem from category theory are not very good at communicating their intent in programming. (my words) Monad could be named Flatmappable f.i. 'unit' and 'bind' can have more intuïtive names as well.
At the moment I get the impression that as Scala is becoming a safe and productive and widely used tool there are developers moving to more Haskell like pastures within Scala. Perhaps because that kind of programming is required for some specific problems. But quite likely as well because they hope that it will make them stand out as smarter programmers.
Some people may remember the so called "Peters principle". Informally it states that people get promoted until they've reached their level of incompetence.
Similarly some smart developers tend to increase the complexity of their code to keep themselves amused until they're struggling to understand it themselves. Joosts principle. :-)
Edit: the link to the talk https://www.infoq.com/presentations/functional-pros-cons
This was my point exactly, also thanks for the link I'll have to checkout that talk :-)
I'm actually indifferent to the terminology, having used my fair share of Haskell/ML/Lisp, but I can see how you came to that assumption.
> in many formal publications
I'm aware of this, but the thing with this is not everyone in software has a computer science background, let alone an academic background. I'm a freelancer at the moment, but if I used most of this terminology in my workplace people would be giving me wtf looks.
> In no way is "Enterprise Java Beans" analogous
How so? All I said formal names in mathematic/computer science, give next to intuition into their actual meaning & when you look up their meaning, most of the results are riddled with more terminology. Same kind of goes for a lot of the Jagon in Java enterprise stuff, like beans/services/factories/etc. I wasn't saying their exactly the same, but more I had a similar experience when trying to familiarise myself with that stuff.
Didn't really expect that, but bravo, I suppose!
By coincidence, I was reading the official guide to Futures yesterday: http://docs.scala-lang.org/overviews/core/futures.html
And was (pleasantly) surprised to find that it contains the sentence "Try[T] is similar to Option[T] or Either[T, S], in that it is a monad potentially holding a value of some type" as well as a later reference to "monadic operations without side-effects".
I'm fully on board with you...I think Scalaz as a library is a virus, and it's community is toxic, and it's desperate desire to turn Scala into Haskell ends up turning an awesome ML-inspired language into a vastly inferior religious (...ahem, pure) language.
But Cats and Shapeless aren't Scalaz. They have concepts that happen to exist in Haskell, but they aren't Haskell's concepts to own any more than C owns imperative programming. If anything, Mathematics owns the concepts and Haskell happened to borrow them to make a terrible purist concept slightly more practical. It turns out that when you need the concepts (and I have, on a couple of occasions), it makes Scala slightly more practical as well.
We use it extensively at Verizon, and it exists just fine with 'impure' code, Akka code, or whatever else various teams decide to also pull in. Codebases that don't use Scalaz end up re-inventing it, usually in a more buggy way and at a waste of developer effort.
Reinventing is fine on your own for a learning exercise and I certainly did it a few times, but in production code, just use Scalaz. Or sure, I suppose if you want to use a copy and pasted into a new repo version of Scalaz, go for Cats. I don't even know why Shapeless is brought into the conversation, it has a much more narrow use case and I almost never reach for it.
I've also found the Scalaz community and chat room on IRC quite helpful, whereas I've had some really unpleasant interactions with Cats committers. To go around spreading FUD and promoting an alpha level library that's less than half as popular as Scalaz (according to Github stars) is just irresponsible.
The main thing scalaz has that cats doesn't is scalaz.concurrent.Task, and there are multiple typelevel-endorsed alternatives to it being worked on as well (in monix and fs2). Task is wonderful btw.
fwiw we use scalaz at work and haven't upgraded to cats because it isn't ready. cats just fixed a performance bug that would have destroyed us (Map union mappend was ridiculously unoptimized compared to scalaz's). We .foldMap(/* make a small Map*/) all the time and it's one of our favorite parts of scalaz. see https://github.com/typelevel/cats/issues/1290 for the bug.
Typelevel didn't even want to fork Scalaz to begin with. That was only their plan B, plan A was to take over the community with code of conduct/social justice shenanigans, and then expel people they didn't like. The fork is just what they came up with after dibblegate failed.
They need to move their lazy asses to Haskell and start fixing and implementing the tooling there instead of enjoying their free ride in Scala while constantly shitting on the language and its community.
https://groups.google.com/forum/#!topic/scalaz/9X_putSGoCY
https://groups.google.com/forum/#!searchin/scalaz/code$20of$...
Calling Tony Morris a rapist was probably the highlight of the affair: https://twitter.com/shajra/status/544712807220908032
Up until they realized they couldn't take over the community, Lars Hupel and Miles Sabin had no publicly stated plans to leave Scalaz.
Cats initial commit is early 2015.
https://github.com/typelevel/cats/commits/master?page=74
I have no idea why everyone dislikes them so much. I use Scalaz, and it's pretty great. From what I've seen Cats is nearly the same thing, I just saw no reason to switch. In what way do you believe Cats is significantly different from Scalaz, beyond the fact that you apparently dislike the people involved?
Incidentally, scalaz-streaming was also pretty nice - mathematically I liked it but it was simply not as performant as Akka streaming. I'd love to use it if it becomes fast.
I even use vars where it is appropriate! :)
Some feel it should go full FP (what I mean by that is really discourage OOP, side effects, etc...). There is some valid arguments as Rust and Haskell might end up being an easier language to master as you can completely avoid the OOP conversation (polymorphic inheritance seems incredibly simple yet there are whole books written on how to use it.. ie patterns).
I'm curious do you prefer a more OOP imperative approach with some FP or do you prefer the opposite (FP with some slight OOP)?
So, when a language appeared to combine the best ideas from FP and OOP, I happily embraced it. And I want it to stay this way.
However, Scala is not Haskell. Scala's raison d'être is merging FP and OOP, and it excels at it. I'd like to leave it this way.
In Scala you can use var, which is easy.
In Haskell you can write your algorithm using ST and then use it as a pure function by means of runST. The type system guarantees that all such state is local to the invocation.