News for hackers. Stuff that matters.
Re:Maybe Functions by wesselbindt on Monday March 11, 2024 @12:54PM (#39670581)
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).

There are no comments on this comment yet.