by risto1 · 8y ago · 0 comments
I've heard 'Professor Frisbee's Mostly Adequate Guide to Functional Programming' is ok, but I'm looking at the section on monads and the monad laws aren't even mentioned. Which is a huge red flag for me, because without the laws it isn't a monad and you can get really strange behavior if you use it like that. I would avoid reading that book
People write these tutorials because they want to improve their portfolio to further their career, but they often don't even understand it yet -- a perfect example of a perverse incentive.
An example is the guy who wrote "You Don't Know Js" [1]. All of these are completely wrong statements:
- "But what I will say is that a monad is basically a value type."
- "A monad is a data structure. It's a type."
- "Actually, a monad isn't a single data type, it's really more like a related collection of data types. It's kind of an interface that's implemented differently depending on the needs of different values. Each implementation is a different type of monad."
- Says "methods" a bunch of times, there are no methods involved with monads in any way, it's FP
- His example in "Just a Monad" isn't a monad
- "Actually, the Maybe monad is a particular pairing of two other simpler monads: Just and Nothing"
- "Many implementations of a JavaScript Maybe monad include a check (usually in map(..)) to see if the value is null/undefined, and skipping the behavior if so" - that makes it not a monad, it violates the laws. Java's Optional type isn't a monad for similar reasons
- "But... that approach to Maybe is not a pure monad." - there's no pure/impure monads, it's either a monad or it isn't
- "The core spirit of a Monad says that it must be valid for all values and cannot do any inspection of the value, at all -- not even a null check. So those other implementations are cutting corners for the sake of convenience. It's not a huge deal," - It is a huge deal, a whole lot of abstractions are built on top of monads, if it doesn't satisfy the laws exactly then you'll be entering a world of pain you really wish you didn't
I stopped reading the rest but you get the point. You don't want to end up in a situation where you have to unlearn a bunch of this stuff. Btw the guy who wrote the Professor Frisbee book wrote the foreword in this book, so you can see why a lot of this stuff raises red flags for experienced FPers. My suggestion is to read fantasy land and ask questions on an FP channel
[1] https://github.com/getify/Functional-Light-JS/blob/master/ma...
No comments yet.