3 ms·
You're describing a functor. For monads, you still need bind or join.
by maleldil 1y ago
You're describing a functor. For monads, you still need bind or join.
- ww520 1y agoIt's not a functor; "map" is bind. Here's an example in non-Haskell as I was addressing non-Haskell audience. class Maybe { value: int; static wrap(v: int) { return new Maybe { value = v } } // map() applies fn on the unwrapped value. fn returns a Maybe. map(fn: (x: int) => Maybe) { return this.value == null ? Maybe.wrap(null) : fn(this.value); } } Here Maybe.wrap() is "unit" and Maybe.map() is "bind" in Haskell lingo. The whole thing is a monad. You can chain call with it. Maybe.wrap(5) .map(x => Maybe.wrap(x + 1)) .map(x => Maybe.wrap(x * 2))
- maleldil 1y agoHaskell bind is usually spelt flatMap in other languages, like Rust and even Java. map is used for functor fmap.