Copyright | (C) 2013 Amgen Inc. |
---|---|
Safe Haskell | None |
Language | Haskell2010 |
Interaction with an instance of R. The interface in this module allows for instantiating an arbitrary number of concurrent R sessions, even though currently the R library only allows for one global instance, for forward compatibility.
The R
monad defined here serves to give static guarantees that an instance
is only ever used after it has been initialized and before it is finalized.
Doing otherwise should result in a type error. This is done in the same way
that the ST
monad encapsulates side effects: by assigning
a rank-2 type to the only run function for the monad.
This module is intended to be imported qualified.
The R monad
The R
monad, for sequencing actions interacting with a single instance of
the R interpreter, much as the IO
monad sequences actions interacting with
the real world. The R
monad embeds the IO
monad, so all IO
actions can
be lifted to R
actions.
Monad (R s) Source # | |
Functor (R s) Source # | |
Applicative (R s) Source # | |
MonadIO (R s) Source # | |
PrimMonad (R s) Source # | |
MonadThrow (R s) Source # | |
MonadMask (R s) Source # | |
MonadCatch (R s) Source # | |
MonadR (R s) Source # | |
(NFData c, Literal a a0, Literal b b0, Literal c c0) => Literal (a -> b -> R s c) ExtPtr Source # | |
(NFData b, Literal a a0, Literal b b0) => Literal (a -> R s b) ExtPtr Source # | |
(NFData a1, Literal a2 i1, Literal a3 i2, Literal a4 i3, Literal a1 i4) => Literal (a2 -> a3 -> a4 -> R s a1) ExtPtr Source # | |
(NFData a1, Literal a2 i1, Literal a3 i2, Literal a4 i3, Literal a5 i4, Literal a1 i5) => Literal (a2 -> a3 -> a4 -> a5 -> R s a1) ExtPtr Source # | |
(NFData a1, Literal a2 i1, Literal a3 i2, Literal a4 i3, Literal a5 i4, Literal a6 i5, Literal a1 i6) => Literal (a2 -> a3 -> a4 -> a5 -> a6 -> R s a1) ExtPtr Source # | |
(NFData a1, Literal a2 i1, Literal a3 i2, Literal a4 i3, Literal a5 i4, Literal a6 i5, Literal a7 i6, Literal a1 i7) => Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> R s a1) ExtPtr Source # | |
(NFData a1, Literal a2 i1, Literal a3 i2, Literal a4 i3, Literal a5 i4, Literal a6 i5, Literal a7 i6, Literal a8 i7, Literal a1 i8) => Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> R s a1) ExtPtr Source # | |
(NFData a1, Literal a2 i1, Literal a3 i2, Literal a4 i3, Literal a5 i4, Literal a6 i5, Literal a7 i6, Literal a8 i7, Literal a9 i8, Literal a1 i9) => Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> R s a1) ExtPtr Source # | |
(NFData a1, Literal a2 i1, Literal a3 i2, Literal a4 i3, Literal a5 i4, Literal a6 i5, Literal a7 i6, Literal a8 i7, Literal a9 i8, Literal a10 i9, Literal a1 i10) => Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> a10 -> R s a1) ExtPtr Source # | |
(NFData a1, Literal a2 i1, Literal a3 i2, Literal a4 i3, Literal a5 i4, Literal a6 i5, Literal a7 i6, Literal a8 i7, Literal a9 i8, Literal a10 i9, Literal a11 i10, Literal a1 i11) => Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> a10 -> a11 -> R s a1) ExtPtr Source # | |
(NFData a1, Literal a2 i1, Literal a3 i2, Literal a4 i3, Literal a5 i4, Literal a6 i5, Literal a7 i6, Literal a8 i7, Literal a9 i8, Literal a10 i9, Literal a11 i10, Literal a12 i11, Literal a1 i12) => Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> a10 -> a11 -> a12 -> R s a1) ExtPtr Source # | |
(NFData a1, Literal a2 i1, Literal a3 i2, Literal a4 i3, Literal a5 i4, Literal a6 i5, Literal a7 i6, Literal a8 i7, Literal a9 i8, Literal a10 i9, Literal a11 i10, Literal a12 i11, Literal a13 i12, Literal a1 i13) => Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> a10 -> a11 -> a12 -> a13 -> R s a1) ExtPtr Source # | |
(NFData a, Literal a b) => Literal (R s a) ExtPtr Source # | |
type PrimState (R s) Source # | |
data ExecContext (R s) Source # | |
runRegion :: NFData a => (forall s. R s a) -> IO a Source #
Run an R action in the global R instance from the IO monad. This action
provides no static guarantees that the R instance was indeed initialized and
has not yet been finalized. Make sure to call it within the scope of
withEmbeddedR
.
runRegion m
fully evaluates the result of action m
, to ensure that no
thunks hold onto resources in a way that would extrude the scope of the
region. This means that the result must be first-order data (i.e. not
a function).
R instance creation
Configuration options for the R runtime. Configurations form monoids, so arguments can be accumulated left-to-right through monoidal composition.
Config | |
|
defaultConfig :: Config Source #
Default argument to pass to initialize
.
withEmbeddedR :: Config -> IO a -> IO a Source #
Initialize a new instance of R, execute actions that interact with the
R instance and then finalize the instance. This is typically called at the
very beginning of the main
function of the program.
main = withEmbeddedR $ do {...}
Note that R does not currently support reinitialization after finalization,
so this function should be called only once during the lifetime of the
program (see srcunixsystem.c:Rf_initialize()
in the R source code).
initialize :: Config -> IO () Source #
Create a new embedded instance of the R interpreter. Only works from the
main thread of the program. That is, from the same thread of execution that
the program's main
function is running on. In GHCi, use -fno-ghci-sandbox
to achieve this.