{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE DefaultSignatures #-}
module Control.Monad.R.Class
( MonadR(..)
, Region
, acquireSome
) where
import Control.Memory.Region
import Foreign.R
import Control.Applicative
import Control.Monad.Catch (MonadCatch, MonadMask)
import Control.Monad.Trans (MonadIO(..))
import Control.Monad.Primitive (PrimMonad, PrimState)
import Prelude
class (Applicative m, MonadIO m, MonadCatch m, MonadMask m, PrimMonad m)
=> MonadR m where
io :: IO a -> m a
io = liftIO
acquire :: s ~ V => SEXP s a -> m (SEXP (Region m) a)
default acquire :: (MonadIO m, Region m ~ G) => SEXP s a -> m (SEXP (Region m) a)
acquire = liftIO . protect
data ExecContext m :: *
getExecContext :: m (ExecContext m)
unsafeRunWithExecContext :: m a -> ExecContext m -> IO a
type Region m = PrimState m
acquireSome :: (MonadR m) => SomeSEXP V -> m (SomeSEXP (Region m))
acquireSome (SomeSEXP s) = SomeSEXP <$> acquire s