1695 shaares
869 private links
869 private links
I never know there is a van Laarhoven's representation of Free Monad! What's more, van Laarhoven free monad can be used to implement extensible algebraic effects (see https://hackage.haskell.org/package/free-vl). Isn't that awesome?
newtype VLMonad ops a = VLMonad { runVLMonad :: forall m. Monad m => ops m -> m a }
instance Monad (VLMonad ops) where
return a = VLMonad (\_ -> return a)
m >>= f = VLMonad (\ops -> runVLMonad m ops >>= f' ops)
where
f' ops a = runVLMonad (f a) ops