3 ms·
That's not a monad, that's just a functor. And that's great, because functors are easier to grok than monads! A functor F consists of two things: - a kind of f
by wesselbindt 3y ago
That's not a monad, that's just a functor. And that's great, because functors are easier to grok than monads! A functor F consists of two things:
- a kind of function on types which transforms any type T to some new type F(T)
- a rule which associates to any function f: T -> S a function fmap(f): F(T) -> F(S)
That's exactly what the author defines here, to a type T we associate Maybe<T>, and to a function f: T -> S we associate `fmap(f)(x) = None if x is None else f(x)`.
A monad needs some structure in addition to fmap, namely bind and return. These allow you to take a function T -> F(S) and a function S -> F(U) and compose them together to a function T -> F(U).
- deleted 3y ago[deleted]