{- |
These functions work in arbitrary monads
but are especially helpful when working with the CodeGenFunction monad.
-}
module LLVM.Extra.Monad where

import Control.Monad (liftM2, liftM3, join, (<=<), )


chain :: (Monad m) => [a -> m a] -> (a -> m a)
chain =
   foldr (flip (<=<)) return

liftR2 :: (Monad m) => (a -> b -> m c) -> m a -> m b -> m c
liftR2 f ma mb =
   join (liftM2 f ma mb)

liftR3 :: (Monad m) => (a -> b -> c -> m d) -> m a -> m b -> m c -> m d
liftR3 f ma mb mc =
   join (liftM3 f ma mb mc)