ekmett / kan-extensions

Kan extensions, Kan lifts, the Yoneda lemma, and (co)monads generated by a functor
Other
79 stars 33 forks source link

Document reason for implementation choice for Monad (Yoneda m) #25

Open treeowl opened 8 years ago

treeowl commented 8 years ago
Yoneda m >>= k = Yoneda (\f -> m id >>= \a -> runYoneda (k a) f)

I believe an alternative would be

Yoneda m >>= k = Yoneda (\f -> join . m $ \a -> runYoneda (k a) f)

The most obvious reason to prefer the current implementation is that it can take advantage of fmap id = id optimizations in some situations. Is this the only reason?