4 ms·
The problem with monads is just the words. "bind" in particular is a bad term!
by sixo 3y ago
The problem with monads is just the words. "bind" in particular is a bad term!
- sdeframond 3y agoIt make sense in some contexts: it binds the value produced by the monad to a new name. For example, it binds (or "assigns") the value read from a file to the variable x. I agree that `flatMap` is clearer when manipulating lists, which is probably a better first approach than the IO monad. However `flatMap` would sound weird for IO monad, I think. What I find confusing is using the do notation for monads with very different meaning. Code looks the same but it does something totally different! I wonder if putting the Monad interface ("typeclass") front and center in Haskell is such a good idea. Kinda feels like premature abstraction. We should use descriptive names instead of opaque abstractions. ...or maybe I haven't seen the light yet.
- kagakuninja 3y agoI'm using Scala syntax here... If I have: val a = IO(42) def f(n: Int) = IO(n) And I use map, then I get: val r: IO[IO[Int]] = a.map(f) Which we don't want... the solution is to flatten it. This can be done with flatten, or flatMap: a.map(f).flatten a.flatMap(f) Both produce IO[Int], and this makes sense to me using any monad. By contrast, bind means nothing to me.