|
|
|
|
|
by a1369209993
1876 days ago
|
|
> But monads don't compose with each other, do they? They do if they're[0] traversable (cf literally `Data.Traversable` in Haskell), which almost all specific monads are. You'd have something like: newtype Comp f1 f2 a = Comp { unComp :: (f1 (f2 a)) }
instance (Monad f1,Monad f2,Traversable f2) => Monad (Comp f1 f2) where
(Comp a) >>= k = Comp $ a >>= (map join . traverse (unComp . k))
Edit: 0: actually, only the inner monad needs to be traversable. |
|
[0]: https://stackoverflow.com/questions/42284879/is-the-composit...