-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Seamlessly call R from Haskell and vice versa. No FFI required. -- -- For up to date Haddock documentation, please see -- http://www.stackage.org/package/inline-r. @package inline-r @version 1.0.1 -- | Phantom type indices for segregating values into "regions" of memory, -- which are markers that serve as static conservative approximations of -- the liveness of an object. That is, regions have scopes, and objects -- within a region are guaranteed to remain live within the scope of that -- region. module Control.Memory.Region -- | The global region is a special region whose scope extends all the way -- to the end of the program. As such, any object allocated within this -- region lives "forever". In this sense, it is the top-level region, -- whose scope includes all other regions. type GlobalRegion = RealWorld -- | Void is not a region. It is a placeholder marking the absence of -- region. Useful to tag objects that belong to no region at all. data Void -- | Convenient shorthand. type G = GlobalRegion -- | Convenient shorthand. type V = Void -- | A partial order on regions. In fact regions form a lattice, with -- GlobalRegion being the supremum and Void the infimum. type family a <= b :: Constraint -- | Bindings for R/Rembedded.h, containing entry points -- for running an instance of R embedded within another program. module Foreign.R.Embedded -- | Initialize R. initEmbeddedR :: Int -> Ptr CString -> IO () endEmbeddedR :: Int -> IO () -- | Character encodings. module Foreign.R.Encoding -- | Content encoding. data CEType CE_Native :: CEType CE_UTF8 :: CEType CE_Latin1 :: CEType CE_Bytes :: CEType CE_Symbol :: CEType CE_Any :: CEType instance GHC.Show.Show Foreign.R.Encoding.CEType instance GHC.Classes.Eq Foreign.R.Encoding.CEType instance GHC.Enum.Enum Foreign.R.Encoding.CEType -- | Exception type wrapping errors thrown by the R runtime. module Foreign.R.Error data RError RError :: String -> RError instance GHC.Show.Show Foreign.R.Error.RError instance GHC.Exception.Type.Exception Foreign.R.Error.RError -- | Bindings for R/R_ext/eventloop.h, for building event -- loops. module Foreign.R.EventLoop -- | R input handler chain. Each input handler points to the next. This -- view of input handlers is shallow, in the sense that the -- Storable instance only unmarshalls the first element in the -- chain at any one time. A shallow view allows peek and -- poke to be inlinable. data InputHandler InputHandler :: FunPtr (Ptr () -> IO ()) -> CInt -> CInt -> Fd -> Ptr () -> Ptr InputHandler -> InputHandler -- | The input handler callback. [inputHandlerCallback] :: InputHandler -> FunPtr (Ptr () -> IO ()) -- | Undocumented and currently unused. [inputHandlerActivity] :: InputHandler -> CInt -- | Whether this input handler is activated or deactivated. [inputHandlerActive] :: InputHandler -> CInt -- | The file descriptor ahssociated with this handler. [inputHandlerFD] :: InputHandler -> Fd -- | Callbacks can optionally be passed in arbitrary data. [inputHandlerUserData] :: InputHandler -> Ptr () -- | The next input handler in the chain. [inputHandlerNext] :: InputHandler -> Ptr InputHandler -- | Input handlers used in event loops. inputHandlers :: Ptr (Ptr InputHandler) -- | R_PolledEvents global variable. polledEvents :: Ptr (FunPtr (IO ())) -- | R_wait_usec global variable. pollingPeriod :: Ptr CInt -- | R_PolledEvents global variable. graphicsPolledEvents :: Ptr (FunPtr (IO ())) -- | R_wait_usec global variable. graphicsPollingPeriod :: Ptr CInt checkActivity :: CInt -> CInt -> IO (Ptr FdSet) runHandlers :: Ptr InputHandler -> Ptr FdSet -> IO () -- | Create and register a new InputHandler. The given file -- descriptor should be open in non-blocking read mode. Make sure to -- dispose of the callback using freeHaskellFunPtr after calling -- removeInputHandler where appropriate. addInputHandler :: Ptr InputHandler -> Fd -> FunPtr (Ptr () -> IO ()) -> Int -> IO (Ptr InputHandler) -- | Remove an input handler from an input handler chain. Returns -- True if the handler was successfully removed, False -- otherwise. removeInputHandler :: Ptr InputHandler -> Ptr InputHandler -> IO Bool instance GHC.Show.Show Foreign.R.EventLoop.InputHandler instance GHC.Classes.Eq Foreign.R.EventLoop.InputHandler instance Foreign.Storable.Storable Foreign.R.EventLoop.InputHandler -- | inline-c context. module Foreign.R.Context rCtx :: Context data SEXPREC newtype {-# CTYPE "SEXP" #-} SEXP0 SEXP0 :: Ptr SEXPREC -> SEXP0 [unSEXP0] :: SEXP0 -> Ptr SEXPREC -- | R uses three-valued logic. data {-# CTYPE "Logical" #-} Logical FALSE :: Logical TRUE :: Logical NA :: Logical instance Foreign.Storable.Storable Foreign.R.Context.SEXP0 instance GHC.Classes.Ord Foreign.R.Context.SEXP0 instance GHC.Classes.Eq Foreign.R.Context.SEXP0 instance GHC.Show.Show Foreign.R.Context.Logical instance GHC.Classes.Ord Foreign.R.Context.Logical instance GHC.Classes.Eq Foreign.R.Context.Logical instance Foreign.Storable.Storable Foreign.R.Context.Logical instance GHC.Show.Show Foreign.R.Context.SEXP0 -- | Definition of SEXPTYPE, which classifies the possible forms of -- an R expression (a SEXP). It is normally not necessary to -- import this module directly, since it is reexported by -- Foreign.R. -- -- This is done in a separate module because we want to use hsc2hs rather -- than c2hs for discharging the boilerplate around SEXPTYPE. This -- is because SEXPTYPE is nearly but not quite a true enumeration -- and c2hs has trouble dealing with that. -- -- This module also defines a singleton version of SEXPTYPE, -- called SSEXPTYPE. This is actually a family of types, one for -- each possible SEXPTYPE. Singleton types are a way of emulating -- dependent types in a language that does not have true dependent type. -- They are useful in functions whose result type depends on the value of -- one of its arguments. See e.g. allocVector. module Foreign.R.Type -- | R "type". Note that what R calls a "type" is not what is usually meant -- by the term: there is really only a single type, called SEXP, -- and an R "type" in fact refers to the class or form of -- the expression. -- -- To better illustrate the distinction, note that any sane type system -- normally has the subject reduction property: that the type of -- an expression is invariant under reduction. For example, (x -> -- x) 1 has type SEXPTYPE, and so does the value of this -- expression, 2, have type SEXPTYPE. Yet the form -- of the expression is an application of a function to a literal, while -- the form of its reduct is an integer literal. -- -- We introduce convenient Haskell-like names for forms because this -- datatype is used to index SEXP and other types through the -- DataKinds extension. data SEXPTYPE Nil :: SEXPTYPE Symbol :: SEXPTYPE List :: SEXPTYPE Closure :: SEXPTYPE Env :: SEXPTYPE Promise :: SEXPTYPE Lang :: SEXPTYPE Special :: SEXPTYPE Builtin :: SEXPTYPE Char :: SEXPTYPE Logical :: SEXPTYPE Int :: SEXPTYPE Real :: SEXPTYPE Complex :: SEXPTYPE String :: SEXPTYPE DotDotDot :: SEXPTYPE Any :: SEXPTYPE Vector :: SEXPTYPE Expr :: SEXPTYPE Bytecode :: SEXPTYPE ExtPtr :: SEXPTYPE WeakRef :: SEXPTYPE Raw :: SEXPTYPE S4 :: SEXPTYPE New :: SEXPTYPE Free :: SEXPTYPE Fun :: SEXPTYPE data SSEXPTYPE :: SEXPTYPE -> Type [SNil] :: SSEXPTYPE ('Nil :: SEXPTYPE) [SSymbol] :: SSEXPTYPE ('Symbol :: SEXPTYPE) [SList] :: SSEXPTYPE ('List :: SEXPTYPE) [SClosure] :: SSEXPTYPE ('Closure :: SEXPTYPE) [SEnv] :: SSEXPTYPE ('Env :: SEXPTYPE) [SPromise] :: SSEXPTYPE ('Promise :: SEXPTYPE) [SLang] :: SSEXPTYPE ('Lang :: SEXPTYPE) [SSpecial] :: SSEXPTYPE ('Special :: SEXPTYPE) [SBuiltin] :: SSEXPTYPE ('Builtin :: SEXPTYPE) [SChar] :: SSEXPTYPE ('Char :: SEXPTYPE) [SLogical] :: SSEXPTYPE ('Logical :: SEXPTYPE) [SInt] :: SSEXPTYPE ('Int :: SEXPTYPE) [SReal] :: SSEXPTYPE ('Real :: SEXPTYPE) [SComplex] :: SSEXPTYPE ('Complex :: SEXPTYPE) [SString] :: SSEXPTYPE ('String :: SEXPTYPE) [SDotDotDot] :: SSEXPTYPE ('DotDotDot :: SEXPTYPE) [SAny] :: SSEXPTYPE ('Any :: SEXPTYPE) [SVector] :: SSEXPTYPE ('Vector :: SEXPTYPE) [SExpr] :: SSEXPTYPE ('Expr :: SEXPTYPE) [SBytecode] :: SSEXPTYPE ('Bytecode :: SEXPTYPE) [SExtPtr] :: SSEXPTYPE ('ExtPtr :: SEXPTYPE) [SWeakRef] :: SSEXPTYPE ('WeakRef :: SEXPTYPE) [SRaw] :: SSEXPTYPE ('Raw :: SEXPTYPE) [SS4] :: SSEXPTYPE ('S4 :: SEXPTYPE) [SNew] :: SSEXPTYPE ('New :: SEXPTYPE) [SFree] :: SSEXPTYPE ('Free :: SEXPTYPE) [SFun] :: SSEXPTYPE ('Fun :: SEXPTYPE) -- | The singleton kind-indexed type family. type family Sing :: k -> Type -- | R uses three-valued logic. data {-# CTYPE "Logical" #-} Logical FALSE :: Logical TRUE :: Logical NA :: Logical -- | Used where the R documentation speaks of "pairlists", which are really -- just regular lists. type PairList = List -- | Constraint synonym grouping all vector forms into one class. -- IsVector a holds iff R's is.vector() returns -- TRUE. type IsVector (a :: SEXPTYPE) = (SingI a, a :∈ 'Char : 'Logical : 'Int : 'Real : 'Complex : 'String : 'Vector : 'Expr : 'WeakRef : 'Raw : '[]) -- | Non-atomic vector forms. See src/main/memory.c:SET_VECTOR_ELT -- in the R source distribution. type IsGenericVector (a :: SEXPTYPE) = (SingI a, a :∈ [Vector, Expr, WeakRef]) -- | IsList a holds iff R's is.list() returns -- TRUE. type IsList (a :: SEXPTYPE) = (SingI a, a :∈ 'Char : 'Logical : 'Int : 'Real : 'Complex : 'String : 'Vector : 'Expr : 'WeakRef : 'Raw : List : '[]) -- | IsPairList a holds iff R's is.pairlist() returns -- TRUE. type IsPairList (a :: SEXPTYPE) = (SingI a, a :∈ [List, Nil]) -- | Constraint synonym grouping all expression forms into one class. -- According to R internals, an expression is usually a Lang, but -- can sometimes also be an Expr or a Symbol. type IsExpression (a :: SEXPTYPE) = (SingI a, a :∈ [Lang, Expr, Symbol]) instance Data.Singletons.SingKind Foreign.R.Type.SEXPTYPE instance Data.Singletons.SingI 'Foreign.R.Type.Nil instance Data.Singletons.SingI 'Foreign.R.Type.Symbol instance Data.Singletons.SingI 'Foreign.R.Type.List instance Data.Singletons.SingI 'Foreign.R.Type.Closure instance Data.Singletons.SingI 'Foreign.R.Type.Env instance Data.Singletons.SingI 'Foreign.R.Type.Promise instance Data.Singletons.SingI 'Foreign.R.Type.Lang instance Data.Singletons.SingI 'Foreign.R.Type.Special instance Data.Singletons.SingI 'Foreign.R.Type.Builtin instance Data.Singletons.SingI 'Foreign.R.Type.Char instance Data.Singletons.SingI 'Foreign.R.Type.Logical instance Data.Singletons.SingI 'Foreign.R.Type.Int instance Data.Singletons.SingI 'Foreign.R.Type.Real instance Data.Singletons.SingI 'Foreign.R.Type.Complex instance Data.Singletons.SingI 'Foreign.R.Type.String instance Data.Singletons.SingI 'Foreign.R.Type.DotDotDot instance Data.Singletons.SingI 'Foreign.R.Type.Any instance Data.Singletons.SingI 'Foreign.R.Type.Vector instance Data.Singletons.SingI 'Foreign.R.Type.Expr instance Data.Singletons.SingI 'Foreign.R.Type.Bytecode instance Data.Singletons.SingI 'Foreign.R.Type.ExtPtr instance Data.Singletons.SingI 'Foreign.R.Type.WeakRef instance Data.Singletons.SingI 'Foreign.R.Type.Raw instance Data.Singletons.SingI 'Foreign.R.Type.S4 instance Data.Singletons.SingI 'Foreign.R.Type.New instance Data.Singletons.SingI 'Foreign.R.Type.Free instance Data.Singletons.SingI 'Foreign.R.Type.Fun instance Language.Haskell.TH.Syntax.Lift Foreign.R.Type.SEXPTYPE instance GHC.Show.Show Foreign.R.Type.SEXPTYPE instance GHC.Classes.Ord Foreign.R.Type.SEXPTYPE instance GHC.Classes.Eq Foreign.R.Type.SEXPTYPE instance GHC.Enum.Enum Foreign.R.Type.SEXPTYPE instance Control.DeepSeq.NFData Foreign.R.Type.SEXPTYPE -- | R-specific predicates for encoding form constraints in type -- signatures. There are no actual bindings in this module. module Foreign.R.Constraints -- | The predicate a :∈ as states that a is a member type -- of the set as. type family (a :: SEXPTYPE) :∈ (as :: [SEXPTYPE]) :: Constraint infix 1 :∈ -- | Non unicode wrapper for the :∈ type family. type In a b = a :∈ b -- | Low-level bindings to core R datatypes and functions which depend on -- computing offsets of C struct field. We use hsc2hs for this purpose. module Foreign.R.Internal -- | The basic type of all R expressions, classified by the form of the -- expression, and the memory region in which it has been allocated. newtype SEXP s (a :: SEXPTYPE) SEXP :: SEXP0 -> SEXP s (a :: SEXPTYPE) [unSEXP] :: SEXP s (a :: SEXPTYPE) -> SEXP0 -- | Add a type index to the pointer. sexp :: SEXP0 -> SEXP s a -- | Remove the type index from the pointer. unsexp :: SEXP s a -> SEXP0 -- | Like sexp but for SomeSEXP. somesexp :: SEXP0 -> SomeSEXP s -- | Release object into another region. Releasing is safe so long as the -- target region is "smaller" than the source region, in the sense of -- (<=). release :: t <= s => SEXP s a -> SEXP t a unsafeRelease :: SEXP s a -> SEXP r a unsafeReleaseSome :: SomeSEXP s -> SomeSEXP g -- | A SEXP of unknown form. data SomeSEXP s SomeSEXP :: {-# UNPACK #-} !SEXP s a -> SomeSEXP s -- | Deconstruct a SomeSEXP. Takes a continuation since otherwise -- the existentially quantified variable hidden inside SomeSEXP -- would escape. unSomeSEXP :: SomeSEXP s -> (forall a. SEXP s a -> r) -> r cIntConv :: (Integral a, Integral b) => a -> b cIntToEnum :: Enum a => CInt -> a cUIntFromSingEnum :: SSEXPTYPE a -> CUInt cIntFromEnum :: Enum a => a -> CInt -- | Return the "type" tag (aka the form tag) of the given SEXP. -- This function is pure because the type of an object does not normally -- change over the lifetime of the object. typeOf :: SEXP s a -> SEXPTYPE cTYPEOF :: SEXP0 -> IO CInt unsafeCast :: SEXPTYPE -> SomeSEXP s -> SEXP s b -- | Cast the type of a SEXP into another type. This function is -- partial: at runtime, an error is raised if the source form tag does -- not match the target form tag. cast :: SSEXPTYPE a -> SomeSEXP s -> SEXP s a -- | Cast form of first argument to that of the second argument. asTypeOf :: SomeSEXP s -> SEXP s a -> SEXP s a -- | Unsafe coercion from one form to another. This is unsafe, in the sense -- that using this function improperly could cause code to crash in -- unpredictable ways. Contrary to cast, it has no runtime cost -- since it does not introduce any dynamic check at runtime. unsafeCoerce :: SEXP s a -> SEXP s b isRInteractive :: Ptr CInt -- | Global nil value. Constant throughout the lifetime of the R instance. nilValue :: Ptr (SEXP G Nil) -- | Unbound marker. Constant throughout the lifetime of the R instance. unboundValue :: Ptr (SEXP G Symbol) -- | Missing argument marker. Constant throughout the lifetime of the R -- instance. missingArg :: Ptr (SEXP G Symbol) -- | The base environment. baseEnv :: Ptr (SEXP G Env) -- | The empty environment. emptyEnv :: Ptr (SEXP G Env) -- | Global environment. globalEnv :: Ptr (SEXP G Env) -- | Signal handler switch signalHandlers :: Ptr CInt -- | Flag that shows if computation should be interrupted. interruptsPending :: Ptr CInt -- | Info header for the SEXP data structure. data SEXPInfo SEXPInfo :: SEXPTYPE -> Bool -> Int -> Int -> Bool -> Bool -> Bool -> Bool -> SEXPInfo -- | Type of the SEXP. [infoType] :: SEXPInfo -> SEXPTYPE -- | Is this an object with a class attribute. [infoObj] :: SEXPInfo -> Bool -- | Control copying information. [infoNamed] :: SEXPInfo -> Int -- | General purpose data. [infoGp] :: SEXPInfo -> Int -- | Mark object as 'in use' in GC. [infoMark] :: SEXPInfo -> Bool -- | Debug marker. [infoDebug] :: SEXPInfo -> Bool -- | Trace marker. [infoTrace] :: SEXPInfo -> Bool -- | Alignment (not in use). [infoSpare] :: SEXPInfo -> Bool -- | Extract the header from the given SEXP. peekInfo :: SEXP s a -> IO SEXPInfo cOBJECT :: SEXP0 -> IO CInt cNAMED :: SEXP0 -> IO CInt cLEVELS :: SEXP0 -> IO CInt cMARK :: SEXP0 -> IO CInt cRDEBUG :: SEXP0 -> IO CInt cRTRACE :: SEXP0 -> IO CInt cRSTEP :: SEXP0 -> IO CInt -- | Check if object is an S4 object. -- -- This is a function call so it will be more precise than using -- typeOf. isS4 :: SEXP s ty -> Bool -- | Get the attribute list from the given object. getAttributes :: SEXP s a -> IO (SEXP s b) -- | Get attribute with the given name. getAttribute :: SEXP s a -> SEXP s2 b -> SEXP s c -- | Set the attribute list. setAttributes :: SEXP s a -> SEXP s b -> IO () cAttrib :: SEXP0 -> IO SEXP0 csetAttrib :: SEXP0 -> SEXP0 -> IO () cgetAttrib :: SEXP0 -> SEXP0 -> SEXP0 cisS4 :: SEXP0 -> Int instance Foreign.Storable.Storable (Foreign.R.Internal.SEXP s a) instance GHC.Classes.Ord (Foreign.R.Internal.SEXP s a) instance GHC.Classes.Eq (Foreign.R.Internal.SEXP s a) instance GHC.Show.Show Foreign.R.Internal.SEXPInfo instance GHC.Show.Show (Foreign.R.Internal.SomeSEXP s) instance Foreign.Storable.Storable (Foreign.R.Internal.SomeSEXP s) instance Control.DeepSeq.NFData (Foreign.R.Internal.SomeSEXP s) instance GHC.Show.Show (Foreign.R.Internal.SEXP s a) instance Control.DeepSeq.NFData (Foreign.R.Internal.SEXP s a) -- | Low-level bindings to core R datatypes and functions. Nearly all -- structures allocated internally in R are instances of a -- SEXPREC. A pointer to a SEXPREC is called a SEXP. -- -- To allow for precise typing of bindings to primitive R functions, we -- index SEXPs by SEXPTYPE, which classifies the -- form of a SEXP (see Foreign.R.Type). A function -- accepting SEXP arguments of any type should leave the type -- index uninstantiated. A function returning a SEXP result of -- unknown type should use SomeSEXP. (More precisely, unknown -- types in negative position should be universally -- quantified and unknown types in positive position should be -- existentially quantified). -- -- Bindings to R functions that allocate or are blocking use safe -- ccall's, so garbage collection of the Haskell heap can happen -- concurrently. See the -- <https://ghc.gitlab.haskell.org/ghc/doc/users_guide/exts/ffi.html#foreign-imports-and-multi-threading -- GHC User's Guide> for more. -- -- This module is intended to be imported qualified. module Foreign.R -- | The basic type of all R expressions, classified by the form of the -- expression, and the memory region in which it has been allocated. newtype SEXP s (a :: SEXPTYPE) SEXP :: SEXP0 -> SEXP s (a :: SEXPTYPE) [unSEXP] :: SEXP s (a :: SEXPTYPE) -> SEXP0 -- | A SEXP of unknown form. data SomeSEXP s SomeSEXP :: {-# UNPACK #-} !SEXP s a -> SomeSEXP s -- | Deconstruct a SomeSEXP. Takes a continuation since otherwise -- the existentially quantified variable hidden inside SomeSEXP -- would escape. unSomeSEXP :: SomeSEXP s -> (forall a. SEXP s a -> r) -> r -- | Cast the type of a SEXP into another type. This function is -- partial: at runtime, an error is raised if the source form tag does -- not match the target form tag. cast :: SSEXPTYPE a -> SomeSEXP s -> SEXP s a -- | Cast form of first argument to that of the second argument. asTypeOf :: SomeSEXP s -> SEXP s a -> SEXP s a -- | Unsafe coercion from one form to another. This is unsafe, in the sense -- that using this function improperly could cause code to crash in -- unpredictable ways. Contrary to cast, it has no runtime cost -- since it does not introduce any dynamic check at runtime. unsafeCoerce :: SEXP s a -> SEXP s b -- | Allocate a SEXP. allocSEXP :: SSEXPTYPE a -> IO (SEXP V a) -- | Allocate a pairlist of SEXPs, chained together. allocList :: Int -> IO (SEXP V 'List) -- | Allocate Vector. allocVector :: IsVector a => SSEXPTYPE a -> Int -> IO (SEXP V a) allocVectorProtected :: IsVector a => SSEXPTYPE a -> Int -> IO (SEXP s a) -- | Intern a string name into the symbol table. -- -- If name is not found, it is added to the symbol table. The -- symbol corresponding to the string name is returned. install :: CString -> IO (SEXP V 'Symbol) -- | Initialize a new string vector. mkString :: CString -> IO (SEXP V 'String) -- | Initialize a new character vector (aka a string). mkChar :: CString -> IO (SEXP V 'Char) -- | Content encoding. data CEType CE_Native :: CEType CE_UTF8 :: CEType CE_Latin1 :: CEType CE_Bytes :: CEType CE_Symbol :: CEType CE_Any :: CEType -- | Create Character value with specified encoding mkCharCE :: CEType -> CString -> IO (SEXP V 'Char) mkCharLenCE :: CEType -> CString -> Int -> IO (SEXP V 'Char) mkWeakRef :: SEXP s a -> SEXP s b -> SEXP s c -> Bool -> IO (SEXP V 'WeakRef) -- | Return the "type" tag (aka the form tag) of the given SEXP. -- This function is pure because the type of an object does not normally -- change over the lifetime of the object. typeOf :: SEXP s a -> SEXPTYPE -- | Check if object is an S4 object. -- -- This is a function call so it will be more precise than using -- typeOf. isS4 :: SEXP s ty -> Bool -- | Set the attribute list. setAttributes :: SEXP s a -> SEXP s b -> IO () -- | Get attribute with the given name. getAttribute :: SEXP s a -> SEXP s2 b -> SEXP s c -- | Get the attribute list from the given object. getAttributes :: SEXP s a -> IO (SEXP s b) -- | Allocate a so-called cons cell, in essence a pair of SEXP -- pointers. cons :: SEXP s a -> SEXP s b -> IO (SEXP V 'List) -- | Allocate a so-called cons cell of language objects, in essence a pair -- of SEXP pointers. lcons :: SEXP s a -> SEXP s b -> IO (SEXP V 'Lang) -- | read CAR object value car :: SEXP s a -> IO (SomeSEXP s) -- | read CDR object cdr :: SEXP s a -> IO (SomeSEXP s) -- | read object`s Tag tag :: SEXP s a -> IO (SomeSEXP s) -- | Set the CAR value and return it. setCar :: SEXP s a -> SEXP s b -> IO (SEXP s b) -- | Set the CDR value and return it. setCdr :: SEXP s a -> SEXP s b -> IO (SEXP s b) setTag :: SEXP s a -> SEXP s b -> IO () envFrame :: SEXP s 'Env -> IO (SEXP s PairList) -- | Enclosing environment. envEnclosing :: SEXP s 'Env -> IO (SEXP s 'Env) -- | Hash table associated with the environment, used for faster name -- lookups. envHashtab :: SEXP s 'Env -> IO (SEXP s 'Vector) -- | Closure formals (aka the actual arguments). closureFormals :: SEXP s 'Closure -> IO (SEXP s PairList) -- | The code of the closure. closureBody :: SEXP s 'Closure -> IO (SomeSEXP s) -- | The environment of the closure. closureEnv :: SEXP s 'Closure -> IO (SEXP s 'Env) -- | The code of a promise. promiseCode :: SEXP s 'Promise -> IO (SomeSEXP s) -- | The environment in which to evaluate the promise. promiseEnv :: SEXP s 'Promise -> IO (SomeSEXP s) -- | The value of the promise, if it has already been forced. promiseValue :: SEXP s 'Promise -> IO (SomeSEXP s) -- | Read a name from symbol. symbolPrintName :: SEXP s 'Symbol -> IO (SomeSEXP s) -- | Read value from symbol. symbolValue :: SEXP s 'Symbol -> IO (SomeSEXP s) -- | Read internal value from symbol. symbolInternal :: SEXP s 'Symbol -> IO (SomeSEXP s) -- | Length of the vector. length :: IsVector a => SEXP s a -> IO CInt -- | Read True Length vector field. trueLength :: IsVector a => SEXP s a -> IO CInt -- | Read character vector data char :: SEXP s 'Char -> IO CString -- | Read real vector data. real :: SEXP s 'Real -> IO (Ptr Double) -- | Read integer vector data. integer :: SEXP s 'Int -> IO (Ptr Int32) -- | Read logical vector data. logical :: SEXP s 'Logical -> IO (Ptr Logical) -- | Read complex vector data. complex :: SEXP s 'Complex -> IO (Ptr (Complex Double)) -- | Read raw data. raw :: SEXP s 'Raw -> IO (Ptr CChar) -- | Read string vector data. string :: SEXP s 'String -> IO (Ptr (SEXP s 'Char)) -- | Extract the data pointer from a vector. unsafeSEXPToVectorPtr :: SEXP s a -> Ptr () readVector :: IsGenericVector a => SEXP s a -> Int -> IO (SomeSEXP s) writeVector :: IsGenericVector a => SEXP s a -> Int -> SEXP s b -> IO (SEXP s a) -- | Evaluate any SEXP to its value. eval :: SEXP s a -> SEXP s 'Env -> IO (SomeSEXP V) -- | Try to evaluate expression. tryEval :: SEXP s a -> SEXP s 'Env -> Ptr CInt -> IO (SomeSEXP V) -- | Try to evaluate without printing error/warning messages to stdout. tryEvalSilent :: SEXP s a -> SEXP s 'Env -> Ptr CInt -> IO (SomeSEXP V) -- | Construct a nullary function call. lang1 :: SEXP s a -> IO (SEXP V 'Lang) -- | Construct unary function call. lang2 :: SEXP s a -> SEXP s b -> IO (SEXP V 'Lang) -- | Construct a binary function call. lang3 :: SEXP s a -> SEXP s b -> SEXP s c -> IO (SEXP V 'Lang) -- | Find a function by name. findFun :: SEXP s a -> SEXP s 'Env -> IO (SomeSEXP s) -- | Find a variable by name. findVar :: SEXP s a -> SEXP s 'Env -> IO (SEXP s 'Symbol) -- | Protect a SEXP from being garbage collected by R. It is in -- particular necessary to do so for objects that are not yet pointed by -- any other object, e.g. when constructing a tree bottom-up rather than -- top-down. -- -- To avoid unbalancing calls to protect and unprotect, do -- not use these functions directly but use withProtected instead. protect :: SEXP s a -> IO (SEXP G a) -- | unprotect n unprotects the last n objects that were -- protected. unprotect :: Int -> IO () -- | Unprotect a specific object, referred to by pointer. unprotectPtr :: SEXP G a -> IO () -- | Preserve an object accross GCs. preserveObject :: SEXP s a -> IO () -- | Allow GC to remove an preserved object. releaseObject :: SEXP s a -> IO () -- | Invoke an R garbage collector sweep. gc :: IO () isRInteractive :: Ptr CInt -- | Global nil value. Constant throughout the lifetime of the R instance. nilValue :: Ptr (SEXP G Nil) -- | Unbound marker. Constant throughout the lifetime of the R instance. unboundValue :: Ptr (SEXP G Symbol) -- | Missing argument marker. Constant throughout the lifetime of the R -- instance. missingArg :: Ptr (SEXP G Symbol) -- | The base environment. baseEnv :: Ptr (SEXP G Env) -- | The empty environment. emptyEnv :: Ptr (SEXP G Env) -- | Global environment. globalEnv :: Ptr (SEXP G Env) -- | Signal handler switch signalHandlers :: Ptr CInt -- | Flag that shows if computation should be interrupted. interruptsPending :: Ptr CInt printValue :: SEXP s a -> IO () -- | Info header for the SEXP data structure. data SEXPInfo SEXPInfo :: SEXPTYPE -> Bool -> Int -> Int -> Bool -> Bool -> Bool -> Bool -> SEXPInfo -- | Type of the SEXP. [infoType] :: SEXPInfo -> SEXPTYPE -- | Is this an object with a class attribute. [infoObj] :: SEXPInfo -> Bool -- | Control copying information. [infoNamed] :: SEXPInfo -> Int -- | General purpose data. [infoGp] :: SEXPInfo -> Int -- | Mark object as 'in use' in GC. [infoMark] :: SEXPInfo -> Bool -- | Debug marker. [infoDebug] :: SEXPInfo -> Bool -- | Trace marker. [infoTrace] :: SEXPInfo -> Bool -- | Alignment (not in use). [infoSpare] :: SEXPInfo -> Bool -- | Extract the header from the given SEXP. peekInfo :: SEXP s a -> IO SEXPInfo data SEXPREC newtype {-# CTYPE "SEXP" #-} SEXP0 SEXP0 :: Ptr SEXPREC -> SEXP0 [unSEXP0] :: SEXP0 -> Ptr SEXPREC -- | Add a type index to the pointer. sexp :: SEXP0 -> SEXP s a -- | Remove the type index from the pointer. unsexp :: SEXP s a -> SEXP0 -- | Release object into another region. Releasing is safe so long as the -- target region is "smaller" than the source region, in the sense of -- (<=). release :: t <= s => SEXP s a -> SEXP t a unsafeRelease :: SEXP s a -> SEXP r a unsafeReleaseSome :: SomeSEXP s -> SomeSEXP g -- | Perform an action with resource while protecting it from the garbage -- collection. This function is a safer alternative to protect and -- unprotect, guaranteeing that a protected resource gets -- unprotected irrespective of the control flow, much like -- bracket_. withProtected :: IO (SEXP V a) -> (SEXP s a -> IO b) -> IO b -- | Deprecated: Use readVector instead. indexVector :: IsGenericVector a => SEXP s a -> Int -> IO (SomeSEXP s) -- | Bindings for R/R_ext/Parse.h. module Foreign.R.Parse -- | parseVector text num status source parses the input string -- into an AST. source, if provided, names the origin of -- text (e.g. a filename). num limits the number of -- expressions to parse, or -1 if no limit. parseVector :: In a [Nil, String] => SEXP s String -> Int -> Ptr CInt -> SEXP s a -> IO (SEXP s Expr) -- | The return code of a call to parseVector, indicating whether -- the parser failed or succeeded. data ParseStatus PARSE_NULL :: ParseStatus PARSE_OK :: ParseStatus PARSE_INCOMPLETE :: ParseStatus PARSE_ERROR :: ParseStatus PARSE_EOF :: ParseStatus instance GHC.Show.Show Foreign.R.Parse.ParseStatus instance GHC.Classes.Eq Foreign.R.Parse.ParseStatus instance GHC.Enum.Enum Foreign.R.Parse.ParseStatus module Data.Vector.SEXP.Base -- | Function from R types to the types of the representations of each -- element in the vector. type family ElemRep s (a :: SEXPTYPE) -- | ElemRep in the form of a relation, for convenience. type E s a b = ElemRep s a ~ b -- | Constraint synonym for all operations on vectors. type VECTOR s ty a = (Storable a, IsVector ty, SingI ty) -- | Constraint synonym for all operations on vectors. type SVECTOR ty a = (Storable a, IsVector ty, SingI ty, ElemRep V ty ~ a) -- | Vectors that can be passed to and from R with no copying at all. These -- vectors are wrappers over SEXP vectors used by R. Memory for vectors -- is allocated from the R heap, and in such way that they can be -- converted to a SEXP by simple pointer arithmetic (see -- toSEXP). -- -- Like Data.Vector.Storable.Mutable vectors, the vector type in -- this module adds one extra level of indirection and a small amount of -- storage overhead for maintainging lengths and slice offsets. If you're -- keeping a very large number of tiny vectors in memory, you're better -- off keeping them as SEXPs and calling fromSEXP -- on-the-fly. module Data.Vector.SEXP.Mutable -- | Mutable R vector. Represented in memory with the same header as -- SEXP nodes. The second type parameter is phantom, reflecting at -- the type level the tag of the vector when viewed as a SEXP. The -- tag of the vector and the representation type are related via -- ElemRep. data MVector s ty a -- | O(1) Create a vector from a SEXP. fromSEXP :: VECTOR s ty a => SEXP s ty -> MVector s ty a -- | O(1) in the common case, O(n) for proper slices. Convert -- a mutable vector to a SEXP. This can be done efficiently, -- without copy, because vectors in this module always include a -- SEXP header immediately before the vector data in memory. toSEXP :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m (SEXP (Region m) ty) release :: s' <= s => MVector s ty a -> MVector s' ty a unsafeRelease :: MVector s ty a -> MVector s' ty a -- | Length of the mutable vector. length :: VECTOR s ty a => MVector s ty a -> Int -- | Check whether the vector is empty. null :: VECTOR s ty a => MVector s ty a -> Bool -- | Create a mutable vector of the given length. new :: forall m ty a. (MonadR m, VECTOR (Region m) ty a) => Int -> m (MVector (Region m) ty a) -- | Create a mutable vector of the given length. The length is not -- checked. unsafeNew :: (MonadR m, VECTOR (Region m) ty a) => Int -> m (MVector (Region m) ty a) -- | Create a mutable vector of the given length (0 if the length is -- negative) and fill it with an initial value. replicate :: (MonadR m, VECTOR (Region m) ty a) => Int -> a -> m (MVector (Region m) ty a) -- | Create a mutable vector of the given length (0 if the length is -- negative) and fill it with values produced by repeatedly executing the -- monadic action. replicateM :: (MonadR m, VECTOR (Region m) ty a) => Int -> m a -> m (MVector (Region m) ty a) -- | Create a copy of a mutable vector. clone :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m (MVector (Region m) ty a) -- | Yield a part of the mutable vector without copying it. slice :: VECTOR s ty a => Int -> Int -> MVector s ty a -> MVector s ty a init :: VECTOR s ty a => MVector s ty a -> MVector s ty a tail :: VECTOR s ty a => MVector s ty a -> MVector s ty a take :: VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a drop :: VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a splitAt :: VECTOR s ty a => Int -> MVector s ty a -> (MVector s ty a, MVector s ty a) -- | Yield a part of the mutable vector without copying it. No bounds -- checks are performed. unsafeSlice :: VECTOR s ty a => Int -> Int -> MVector s ty a -> MVector s ty a unsafeInit :: VECTOR s ty a => MVector s ty a -> MVector s ty a unsafeTail :: VECTOR s ty a => MVector s ty a -> MVector s ty a unsafeTake :: VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a unsafeDrop :: VECTOR s ty a => Int -> MVector s ty a -> MVector s ty a -- | Check whether two vectors overlap. overlaps :: VECTOR s ty a => MVector s ty a -> MVector s ty a -> Bool -- | Reset all elements of the vector to some undefined value, clearing all -- references to external objects. This is usually a noop for unboxed -- vectors. clear :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> m () -- | Yield the element at the given position. read :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> m a -- | Replace the element at the given position. write :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> a -> m () -- | Swap the elements at the given positions. swap :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> Int -> m () -- | Yield the element at the given position. No bounds checks are -- performed. unsafeRead :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> m a -- | Replace the element at the given position. No bounds checks are -- performed. unsafeWrite :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> a -> m () -- | Swap the elements at the given positions. No bounds checks are -- performed. unsafeSwap :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> Int -> Int -> m () -- | Set all elements of the vector to the given value. set :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> a -> m () -- | Copy a vector. The two vectors must have the same length and may not -- overlap. copy :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m () -- | Move the contents of a vector. The two vectors must have the same -- length. -- -- If the vectors do not overlap, then this is equivalent to copy. -- Otherwise, the copying is performed as if the source vector were -- copied to a temporary vector and then the temporary vector was copied -- to the target vector. move :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m () -- | Copy a vector. The two vectors must have the same length and may not -- overlap. This is not checked. unsafeCopy :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m () -- | Move the contents of a vector. The two vectors must have the same -- length, but this is not checked. -- -- If the vectors do not overlap, then this is equivalent to -- unsafeCopy. Otherwise, the copying is performed as if the -- source vector were copied to a temporary vector and then the temporary -- vector was copied to the target vector. unsafeMove :: (MonadR m, VECTOR (Region m) ty a) => MVector (Region m) ty a -> MVector (Region m) ty a -> m () -- | Vectors that can be passed to and from R with no copying at all. These -- vectors are an instance of Data.Vector.Storable, where the -- memory is allocated from the R heap, in such a way that they can be -- converted to a SEXP through simple pointer arithmetic (see -- toSEXP) in constant time. -- -- The main difference between Data.Vector.SEXP and -- Data.Vector.Storable is that the former uses a header-prefixed -- data layout (the header immediately precedes the payload of the -- vector). This means that no additional pointer dereferencing is needed -- to reach the vector data. The trade-off is that most slicing -- operations are O(N) instead of O(1). -- -- If you make heavy use of slicing, then it's best to convert to a -- Data.Vector.Storable vector first, using -- unsafeToStorable. -- -- Note that since unstream relies on slicing operations, it -- will still be an O(N) operation but it will copy vector data twice -- (instead of once). module Data.Vector.SEXP -- | Immutable vectors. The second type paramater is a phantom parameter -- reflecting at the type level the tag of the vector when viewed as a -- SEXP. The tag of the vector and the representation type are -- related via ElemRep. data Vector (ty :: SEXPTYPE) a Vector :: {-# UNPACK #-} !ForeignSEXP ty -> {-# UNPACK #-} !Int32 -> {-# UNPACK #-} !Int32 -> Vector (ty :: SEXPTYPE) a [vectorBase] :: Vector (ty :: SEXPTYPE) a -> {-# UNPACK #-} !ForeignSEXP ty [vectorOffset] :: Vector (ty :: SEXPTYPE) a -> {-# UNPACK #-} !Int32 [vectorLength] :: Vector (ty :: SEXPTYPE) a -> {-# UNPACK #-} !Int32 -- | Mutable R vector. Represented in memory with the same header as -- SEXP nodes. The second type parameter is phantom, reflecting at -- the type level the tag of the vector when viewed as a SEXP. The -- tag of the vector and the representation type are related via -- ElemRep. data MVector s ty a MVector :: {-# UNPACK #-} !SEXP s ty -> {-# UNPACK #-} !Int32 -> {-# UNPACK #-} !Int32 -> MVector s ty a [mvectorBase] :: MVector s ty a -> {-# UNPACK #-} !SEXP s ty [mvectorOffset] :: MVector s ty a -> {-# UNPACK #-} !Int32 [mvectorLength] :: MVector s ty a -> {-# UNPACK #-} !Int32 -- | Function from R types to the types of the representations of each -- element in the vector. type family ElemRep s (a :: SEXPTYPE) -- | Constraint synonym for all operations on vectors. type VECTOR s ty a = (Storable a, IsVector ty, SingI ty) -- | Constraint synonym for all operations on vectors. type SVECTOR ty a = (Storable a, IsVector ty, SingI ty, ElemRep V ty ~ a) -- | O(n) Create an immutable vector from a SEXP. Because -- SEXPs are mutable, this function yields an immutable -- copy of the SEXP. fromSEXP :: SVECTOR ty a => SEXP s ty -> Vector ty a -- | O(1) Unsafe convert a mutable SEXP to an immutable -- vector without copying. The mutable vector must not be used after this -- operation, lest one runs the risk of breaking referential -- transparency. unsafeFromSEXP :: SVECTOR ty a => SEXP s ty -> Vector ty a -- | O(n) Yield a (mutable) copy of the vector as a SEXP. toSEXP :: SVECTOR ty a => Vector ty a -> SEXP s ty -- | O(1) Unsafely convert an immutable vector to a (mutable) -- SEXP without copying. The immutable vector must not be used -- after this operation. unsafeToSEXP :: SVECTOR ty a => Vector ty a -> SEXP s ty -- | O(1) Yield the length of the vector. length :: SVECTOR ty a => Vector ty a -> Int -- | O(1) Test whether a vector if empty null :: SVECTOR ty a => Vector ty a -> Bool -- | O(1) Indexing (!) :: SVECTOR ty a => Vector ty a -> Int -> a -- | O(1) Safe indexing (!?) :: SVECTOR ty a => Vector ty a -> Int -> Maybe a -- | O(1) First element head :: SVECTOR ty a => Vector ty a -> a -- | O(1) Last element last :: SVECTOR ty a => Vector ty a -> a -- | O(1) Unsafe indexing without bounds checking unsafeIndex :: SVECTOR ty a => Vector ty a -> Int -> a -- | O(1) First element without checking if the vector is empty unsafeHead :: SVECTOR ty a => Vector ty a -> a -- | O(1) Last element without checking if the vector is empty unsafeLast :: SVECTOR ty a => Vector ty a -> a -- | O(1) Indexing in a monad. -- -- The monad allows operations to be strict in the vector when necessary. -- Suppose vector copying is implemented like this: -- --
--   copy mv v = ... write mv i (v ! i) ...
--   
-- -- For lazy vectors, v ! i would not be evaluated which means -- that mv would unnecessarily retain a reference to v -- in each element written. -- -- With indexM, copying can be implemented like this instead: -- --
--   copy mv v = ... do
--                     x <- indexM v i
--                     write mv i x
--   
-- -- Here, no references to v are retained because indexing (but -- not the elements) is evaluated eagerly. indexM :: (SVECTOR ty a, Monad m) => Vector ty a -> Int -> m a -- | O(1) First element of a vector in a monad. See indexM -- for an explanation of why this is useful. headM :: (SVECTOR ty a, Monad m) => Vector ty a -> m a -- | O(1) Last element of a vector in a monad. See indexM for -- an explanation of why this is useful. lastM :: (SVECTOR ty a, Monad m) => Vector ty a -> m a -- | O(1) Indexing in a monad without bounds checks. See -- indexM for an explanation of why this is useful. unsafeIndexM :: (SVECTOR ty a, Monad m) => Vector ty a -> Int -> m a -- | O(1) First element in a monad without checking for empty -- vectors. See indexM for an explanation of why this is useful. unsafeHeadM :: (SVECTOR ty a, Monad m) => Vector ty a -> m a -- | O(1) Last element in a monad without checking for empty -- vectors. See indexM for an explanation of why this is useful. unsafeLastM :: (SVECTOR ty a, Monad m) => Vector ty a -> m a -- | O(N) Yield a slice of the vector with copying it. The vector -- must contain at least i+n elements. slice :: SVECTOR ty a => Int -> Int -> Vector ty a -> Vector ty a -- | O(N) Yield all but the last element, this operation will copy -- an array. The vector may not be empty. init :: SVECTOR ty a => Vector ty a -> Vector ty a -- | O(N) Yield at the first n elements with copying. The -- vector may contain less than n elements in which case it is -- returned unchanged. take :: SVECTOR ty a => Int -> Vector ty a -> Vector ty a -- | O(N) Yield all but the first n elements with copying. -- The vector may contain less than n elements in which case an -- empty vector is returned. drop :: SVECTOR ty a => Int -> Vector ty a -> Vector ty a -- | O(N) Copy all but the first element. The vector may not be -- empty. tail :: SVECTOR ty a => Vector ty a -> Vector ty a -- | O(N) Yield the first n elements paired with the -- remainder with copying. -- -- Note that splitAt n v is equivalent to -- (take n v, drop n v) but slightly more -- efficient. splitAt :: SVECTOR ty a => Int -> Vector ty a -> (Vector ty a, Vector ty a) -- | O(N) Yield all but the first element with copying. The vector -- may not be empty but this is not checked. unsafeTail :: SVECTOR ty a => Vector ty a -> Vector ty a -- | O(N) Yield a slice of the vector with copying. The vector must -- contain at least i+n elements but this is not checked. unsafeSlice :: SVECTOR ty a => Int -> Int -> Vector ty a -> Vector ty a -- | O(N) Yield all but the first n elements with copying. -- The vector must contain at least n elements but this is not -- checked. unsafeDrop :: SVECTOR ty a => Int -> Vector ty a -> Vector ty a -- | O(N) Yield the first n elements with copying. The -- vector must contain at least n elements but this is not -- checked. unsafeTake :: SVECTOR ty a => Int -> Vector ty a -> Vector ty a -- | O(N) Yield all but the last element with copying. The vector -- may not be empty but this is not checked. unsafeInit :: SVECTOR ty a => Vector ty a -> Vector ty a -- | O(1) Empty vector empty :: SVECTOR ty a => Vector ty a -- | O(1) Vector with exactly one element singleton :: SVECTOR ty a => a -> Vector ty a -- | O(n) Vector of the given length with the same value in each -- position replicate :: SVECTOR ty a => Int -> a -> Vector ty a -- | O(n) Construct a vector of the given length by applying the -- function to each index generate :: SVECTOR ty a => Int -> (Int -> a) -> Vector ty a -- | O(n) Apply function n times to value. Zeroth element is -- original value. iterateN :: SVECTOR ty a => Int -> (a -> a) -> a -> Vector ty a -- | O(n) Execute the monadic action the given number of times and -- store the results in a vector. replicateM :: (Monad m, SVECTOR ty a) => Int -> m a -> m (Vector ty a) -- | O(n) Construct a vector of the given length by applying the -- monadic action to each index generateM :: (Monad m, SVECTOR ty a) => Int -> (Int -> m a) -> m (Vector ty a) -- | Execute the monadic action and freeze the resulting vector. -- --
--   create (do { v <- new 2; write v 0 'a'; write v 1 'b'; return v }) = <a,b>
--   
create :: SVECTOR ty a => (forall r. ST r (MVector r ty a)) -> Vector ty a -- | O(n) Construct a Vector ty by repeatedly applying the generator -- function to a seed. The generator function yields Just the -- next element and the new seed or Nothing if there are no more -- elements. -- --
--   unfoldr (\n -> if n == 0 then Nothing else Just (n,n-1)) 10
--    = <10,9,8,7,6,5,4,3,2,1>
--   
unfoldr :: SVECTOR ty a => (b -> Maybe (a, b)) -> b -> Vector ty a -- | O(n) Construct a vector with at most n by repeatedly -- applying the generator function to the a seed. The generator function -- yields Just the next element and the new seed or -- Nothing if there are no more elements. -- --
--   unfoldrN 3 (\n -> Just (n,n-1)) 10 = <10,9,8>
--   
unfoldrN :: SVECTOR ty a => Int -> (b -> Maybe (a, b)) -> b -> Vector ty a -- | O(n) Construct a vector with n elements by repeatedly -- applying the generator function to the already constructed part of the -- vector. -- --
--   constructN 3 f = let a = f <> ; b = f <a> ; c = f <a,b> in f <a,b,c>
--   
constructN :: SVECTOR ty a => Int -> (Vector ty a -> a) -> Vector ty a -- | O(n) Construct a vector with n elements from right to -- left by repeatedly applying the generator function to the already -- constructed part of the vector. -- --
--   constructrN 3 f = let a = f <> ; b = f<a> ; c = f <b,a> in f <c,b,a>
--   
constructrN :: SVECTOR ty a => Int -> (Vector ty a -> a) -> Vector ty a -- | O(n) Yield a vector of the given length containing the values -- x, x+1 etc. This operation is usually more efficient -- than enumFromTo. -- --
--   enumFromN 5 3 = <5,6,7>
--   
enumFromN :: (SVECTOR ty a, Num a) => a -> Int -> Vector ty a -- | O(n) Yield a vector of the given length containing the values -- x, x+y, x+y+y etc. This operations is -- usually more efficient than enumFromThenTo. -- --
--   enumFromStepN 1 0.1 5 = <1,1.1,1.2,1.3,1.4>
--   
enumFromStepN :: (SVECTOR ty a, Num a) => a -> a -> Int -> Vector ty a -- | O(n) Enumerate values from x to y. -- -- WARNING: This operation can be very inefficient. If at all -- possible, use enumFromN instead. enumFromTo :: (SVECTOR ty a, Enum a) => a -> a -> Vector ty a -- | O(n) Enumerate values from x to y with a -- specific step z. -- -- WARNING: This operation can be very inefficient. If at all -- possible, use enumFromStepN instead. enumFromThenTo :: (SVECTOR ty a, Enum a) => a -> a -> a -> Vector ty a -- | O(n) Prepend an element cons :: SVECTOR ty a => a -> Vector ty a -> Vector ty a -- | O(n) Append an element snoc :: SVECTOR ty a => Vector ty a -> a -> Vector ty a -- | O(m+n) Concatenate two vectors (++) :: SVECTOR ty a => Vector ty a -> Vector ty a -> Vector ty a infixr 5 ++ -- | O(n) Concatenate all vectors in the list concat :: SVECTOR ty a => [Vector ty a] -> Vector ty a -- | O(n) Yield the argument but force it not to retain any extra -- memory, possibly by copying it. -- -- This is especially useful when dealing with slices. For example: -- --
--   force (slice 0 2 <huge vector>)
--   
-- -- Here, the slice retains a reference to the huge vector. Forcing it -- creates a copy of just the elements that belong to the slice and -- allows the huge vector to be garbage collected. force :: SVECTOR ty a => Vector ty a -> Vector ty a -- | O(m+n) For each pair (i,a) from the list, replace the -- vector element at position i by a. -- --
--   <5,9,2,7> // [(2,1),(0,3),(2,8)] = <3,9,8,7>
--   
(//) :: SVECTOR ty a => Vector ty a -> [(Int, a)] -> Vector ty a -- | Same as (//) but without bounds checking. unsafeUpd :: SVECTOR ty a => Vector ty a -> [(Int, a)] -> Vector ty a -- | O(m+n) For each pair (i,b) from the list, replace the -- vector element a at position i by f a b. -- --
--   accum (+) <5,9,2> [(2,4),(1,6),(0,3),(1,7)] = <5+3, 9+6+7, 2+4>
--   
accum :: SVECTOR ty a => (a -> b -> a) -> Vector ty a -> [(Int, b)] -> Vector ty a -- | Same as accum but without bounds checking. unsafeAccum :: SVECTOR ty a => (a -> b -> a) -> Vector ty a -> [(Int, b)] -> Vector ty a -- | O(n) Reverse a vector reverse :: SVECTOR ty a => Vector ty a -> Vector ty a -- | O(n) Map a function over a vector map :: (SVECTOR ty a, SVECTOR ty b) => (a -> b) -> Vector ty a -> Vector ty b -- | O(n) Apply a function to every element of a Vector ty and its -- index imap :: (SVECTOR ty a, SVECTOR ty b) => (Int -> a -> b) -> Vector ty a -> Vector ty b -- | Map a function over a Vector ty and concatenate the results. concatMap :: (SVECTOR tya a, SVECTOR tyb b) => (a -> Vector tyb b) -> Vector tya a -> Vector tyb b -- | O(n) Apply the monadic action to all elements of the vector, -- yielding a vector of results mapM :: (Monad m, SVECTOR ty a, SVECTOR ty b) => (a -> m b) -> Vector ty a -> m (Vector ty b) -- | O(n) Apply the monadic action to all elements of a Vector ty -- and ignore the results mapM_ :: (Monad m, SVECTOR ty a) => (a -> m b) -> Vector ty a -> m () -- | O(n) Apply the monadic action to all elements of the vector, -- yielding a vector of results. Equvalent to flip mapM. forM :: (Monad m, SVECTOR ty a, SVECTOR ty b) => Vector ty a -> (a -> m b) -> m (Vector ty b) -- | O(n) Apply the monadic action to all elements of a Vector ty -- and ignore the results. Equivalent to flip mapM_. forM_ :: (Monad m, SVECTOR ty a) => Vector ty a -> (a -> m b) -> m () -- | O(min(m,n)) Zip two vectors with the given function. zipWith :: (SVECTOR tya a, SVECTOR tyb b, SVECTOR tyc c) => (a -> b -> c) -> Vector tya a -> Vector tyb b -> Vector tyc c -- | Zip three vectors with the given function. zipWith3 :: (SVECTOR tya a, SVECTOR tyb b, SVECTOR tyc c, SVECTOR tyd d) => (a -> b -> c -> d) -> Vector tya a -> Vector tyb b -> Vector tyc c -> Vector tyd d zipWith4 :: (SVECTOR tya a, SVECTOR tyb b, SVECTOR tyc c, SVECTOR tyd d, SVECTOR tye e) => (a -> b -> c -> d -> e) -> Vector tya a -> Vector tyb b -> Vector tyc c -> Vector tyd d -> Vector tye e zipWith5 :: (SVECTOR tya a, SVECTOR tyb b, SVECTOR tyc c, SVECTOR tyd d, SVECTOR tye e, SVECTOR tyf f) => (a -> b -> c -> d -> e -> f) -> Vector tya a -> Vector tyb b -> Vector tyc c -> Vector tyd d -> Vector tye e -> Vector tyf f zipWith6 :: (SVECTOR tya a, SVECTOR tyb b, SVECTOR tyc c, SVECTOR tyd d, SVECTOR tye e, SVECTOR tyf f, SVECTOR tyg g) => (a -> b -> c -> d -> e -> f -> g) -> Vector tya a -> Vector tyb b -> Vector tyc c -> Vector tyd d -> Vector tye e -> Vector tyf f -> Vector tyg g -- | O(min(m,n)) Zip two vectors with a function that also takes the -- elements' indices. izipWith :: (SVECTOR tya a, SVECTOR tyb b, SVECTOR tyc c) => (Int -> a -> b -> c) -> Vector tya a -> Vector tyb b -> Vector tyc c -- | Zip three vectors and their indices with the given function. izipWith3 :: (SVECTOR tya a, SVECTOR tyb b, SVECTOR tyc c, SVECTOR tyd d) => (Int -> a -> b -> c -> d) -> Vector tya a -> Vector tyb b -> Vector tyc c -> Vector tyd d izipWith4 :: (SVECTOR tya a, SVECTOR tyb b, SVECTOR tyc c, SVECTOR tyd d, SVECTOR tye e) => (Int -> a -> b -> c -> d -> e) -> Vector tya a -> Vector tyb b -> Vector tyc c -> Vector tyd d -> Vector tye e izipWith5 :: (SVECTOR tya a, SVECTOR tyb b, SVECTOR tyc c, SVECTOR tyd d, SVECTOR tye e, SVECTOR tyf f) => (Int -> a -> b -> c -> d -> e -> f) -> Vector tya a -> Vector tyb b -> Vector tyc c -> Vector tyd d -> Vector tye e -> Vector tyf f izipWith6 :: (SVECTOR tya a, SVECTOR tyb b, SVECTOR tyc c, SVECTOR tyd d, SVECTOR tye e, SVECTOR tyf f, SVECTOR tyg g) => (Int -> a -> b -> c -> d -> e -> f -> g) -> Vector tya a -> Vector tyb b -> Vector tyc c -> Vector tyd d -> Vector tye e -> Vector tyf f -> Vector tyg g -- | O(min(m,n)) Zip the two vectors with the monadic action and -- yield a vector of results zipWithM :: (MonadR m, VECTOR (Region m) tya a, VECTOR (Region m) tyb b, VECTOR (Region m) tyc c, ElemRep V tya ~ a, ElemRep V tyb ~ b, ElemRep V tyc ~ c) => (a -> b -> m c) -> Vector tya a -> Vector tyb b -> m (Vector tyc c) -- | O(min(m,n)) Zip the two vectors with the monadic action and -- ignore the results zipWithM_ :: (Monad m, SVECTOR tya a, SVECTOR tyb b) => (a -> b -> m c) -> Vector tya a -> Vector tyb b -> m () -- | O(n) Drop elements that do not satisfy the predicate filter :: SVECTOR ty a => (a -> Bool) -> Vector ty a -> Vector ty a -- | O(n) Drop elements that do not satisfy the predicate which is -- applied to values and their indices ifilter :: SVECTOR ty a => (Int -> a -> Bool) -> Vector ty a -> Vector ty a -- | O(n) Drop elements that do not satisfy the monadic predicate filterM :: (Monad m, SVECTOR ty a) => (a -> m Bool) -> Vector ty a -> m (Vector ty a) -- | O(n) Yield the longest prefix of elements satisfying the -- predicate with copying. takeWhile :: SVECTOR ty a => (a -> Bool) -> Vector ty a -> Vector ty a -- | O(n) Drop the longest prefix of elements that satisfy the -- predicate with copying. dropWhile :: SVECTOR ty a => (a -> Bool) -> Vector ty a -> Vector ty a -- | O(n) Split the vector in two parts, the first one containing -- those elements that satisfy the predicate and the second one those -- that don't. The relative order of the elements is preserved at the -- cost of a sometimes reduced performance compared to -- unstablePartition. partition :: SVECTOR ty a => (a -> Bool) -> Vector ty a -> (Vector ty a, Vector ty a) -- | O(n) Split the vector in two parts, the first one containing -- those elements that satisfy the predicate and the second one those -- that don't. The order of the elements is not preserved but the -- operation is often faster than partition. unstablePartition :: SVECTOR ty a => (a -> Bool) -> Vector ty a -> (Vector ty a, Vector ty a) -- | O(n) Split the vector into the longest prefix of elements that -- satisfy the predicate and the rest with copying. span :: SVECTOR ty a => (a -> Bool) -> Vector ty a -> (Vector ty a, Vector ty a) -- | O(n) Split the vector into the longest prefix of elements that -- do not satisfy the predicate and the rest with copying. break :: SVECTOR ty a => (a -> Bool) -> Vector ty a -> (Vector ty a, Vector ty a) -- | O(n) Check if the vector contains an element elem :: (SVECTOR ty a, Eq a) => a -> Vector ty a -> Bool infix 4 `elem` -- | O(n) Check if the vector does not contain an element (inverse -- of elem) notElem :: (SVECTOR ty a, Eq a) => a -> Vector ty a -> Bool infix 4 `notElem` -- | O(n) Yield Just the first element matching the -- predicate or Nothing if no such element exists. find :: SVECTOR ty a => (a -> Bool) -> Vector ty a -> Maybe a -- | O(n) Yield Just the index of the first element -- matching the predicate or Nothing if no such element exists. findIndex :: SVECTOR ty a => (a -> Bool) -> Vector ty a -> Maybe Int -- | O(n) Yield Just the index of the first occurence of -- the given element or Nothing if the vector does not contain -- the element. This is a specialised version of findIndex. elemIndex :: (SVECTOR ty a, Eq a) => a -> Vector ty a -> Maybe Int -- | O(n) Left fold foldl :: SVECTOR ty b => (a -> b -> a) -> a -> Vector ty b -> a -- | O(n) Left fold on non-empty vectors foldl1 :: SVECTOR ty a => (a -> a -> a) -> Vector ty a -> a -- | O(n) Left fold with strict accumulator foldl' :: SVECTOR ty b => (a -> b -> a) -> a -> Vector ty b -> a -- | O(n) Left fold on non-empty vectors with strict accumulator foldl1' :: SVECTOR ty a => (a -> a -> a) -> Vector ty a -> a -- | O(n) Right fold foldr :: SVECTOR ty a => (a -> b -> b) -> b -> Vector ty a -> b -- | O(n) Right fold on non-empty vectors foldr1 :: SVECTOR ty a => (a -> a -> a) -> Vector ty a -> a -- | O(n) Right fold with a strict accumulator foldr' :: SVECTOR ty a => (a -> b -> b) -> b -> Vector ty a -> b -- | O(n) Right fold on non-empty vectors with strict accumulator foldr1' :: SVECTOR ty a => (a -> a -> a) -> Vector ty a -> a -- | O(n) Left fold (function applied to each element and its index) ifoldl :: SVECTOR ty b => (a -> Int -> b -> a) -> a -> Vector ty b -> a -- | O(n) Left fold with strict accumulator (function applied to -- each element and its index) ifoldl' :: SVECTOR ty b => (a -> Int -> b -> a) -> a -> Vector ty b -> a -- | O(n) Right fold (function applied to each element and its -- index) ifoldr :: SVECTOR ty a => (Int -> a -> b -> b) -> b -> Vector ty a -> b -- | O(n) Right fold with strict accumulator (function applied to -- each element and its index) ifoldr' :: SVECTOR ty a => (Int -> a -> b -> b) -> b -> Vector ty a -> b -- | O(n) Check if all elements satisfy the predicate. all :: SVECTOR ty a => (a -> Bool) -> Vector ty a -> Bool -- | O(n) Check if any element satisfies the predicate. any :: SVECTOR ty a => (a -> Bool) -> Vector ty a -> Bool -- | O(n) Compute the sum of the elements sum :: (SVECTOR ty a, Num a) => Vector ty a -> a -- | O(n) Compute the produce of the elements product :: (SVECTOR ty a, Num a) => Vector ty a -> a -- | O(n) Yield the maximum element of the vector. The vector may -- not be empty. maximum :: (SVECTOR ty a, Ord a) => Vector ty a -> a -- | O(n) Yield the maximum element of the Vector ty according to -- the given comparison function. The vector may not be empty. maximumBy :: SVECTOR ty a => (a -> a -> Ordering) -> Vector ty a -> a -- | O(n) Yield the minimum element of the vector. The vector may -- not be empty. minimum :: (SVECTOR ty a, Ord a) => Vector ty a -> a -- | O(n) Yield the minimum element of the Vector ty according to -- the given comparison function. The vector may not be empty. minimumBy :: SVECTOR ty a => (a -> a -> Ordering) -> Vector ty a -> a -- | O(n) Yield the index of the minimum element of the vector. The -- vector may not be empty. minIndex :: (SVECTOR ty a, Ord a) => Vector ty a -> Int -- | O(n) Yield the index of the minimum element of the Vector ty -- according to the given comparison function. The vector may not be -- empty. minIndexBy :: SVECTOR ty a => (a -> a -> Ordering) -> Vector ty a -> Int -- | O(n) Yield the index of the maximum element of the vector. The -- vector may not be empty. maxIndex :: (SVECTOR ty a, Ord a) => Vector ty a -> Int -- | O(n) Yield the index of the maximum element of the Vector ty -- according to the given comparison function. The vector may not be -- empty. maxIndexBy :: SVECTOR ty a => (a -> a -> Ordering) -> Vector ty a -> Int -- | O(n) Monadic fold foldM :: (Monad m, SVECTOR ty b) => (a -> b -> m a) -> a -> Vector ty b -> m a -- | O(n) Monadic fold with strict accumulator foldM' :: (Monad m, SVECTOR ty b) => (a -> b -> m a) -> a -> Vector ty b -> m a -- | O(n) Monadic fold over non-empty vectors fold1M :: (Monad m, SVECTOR ty a) => (a -> a -> m a) -> Vector ty a -> m a -- | O(n) Monadic fold over non-empty vectors with strict -- accumulator fold1M' :: (Monad m, SVECTOR ty a) => (a -> a -> m a) -> Vector ty a -> m a -- | O(n) Monadic fold that discards the result foldM_ :: (Monad m, SVECTOR ty b) => (a -> b -> m a) -> a -> Vector ty b -> m () -- | O(n) Monadic fold with strict accumulator that discards the -- result foldM'_ :: (Monad m, SVECTOR ty b) => (a -> b -> m a) -> a -> Vector ty b -> m () -- | O(n) Monadic fold over non-empty vectors that discards the -- result fold1M_ :: (Monad m, SVECTOR ty a) => (a -> a -> m a) -> Vector ty a -> m () -- | O(n) Monadic fold over non-empty vectors with strict -- accumulator that discards the result fold1M'_ :: (Monad m, SVECTOR ty a) => (a -> a -> m a) -> Vector ty a -> m () -- | O(n) Prescan -- --
--   prescanl f z = init . scanl f z
--   
-- -- Example: prescanl (+) 0 <1,2,3,4> = <0,1,3,6> prescanl :: (SVECTOR ty a, SVECTOR ty b) => (a -> b -> a) -> a -> Vector ty b -> Vector ty a -- | O(n) Prescan with strict accumulator prescanl' :: (SVECTOR ty a, SVECTOR ty b) => (a -> b -> a) -> a -> Vector ty b -> Vector ty a -- | O(n) Scan -- --
--   postscanl f z = tail . scanl f z
--   
-- -- Example: postscanl (+) 0 <1,2,3,4> = <1,3,6,10> postscanl :: (SVECTOR ty a, SVECTOR ty b) => (a -> b -> a) -> a -> Vector ty b -> Vector ty a -- | O(n) Scan with strict accumulator postscanl' :: (SVECTOR ty a, SVECTOR ty b) => (a -> b -> a) -> a -> Vector ty b -> Vector ty a -- | O(n) Haskell-style scan -- --
--   scanl f z <x1,...,xn> = <y1,...,y(n+1)>
--     where y1 = z
--           yi = f y(i-1) x(i-1)
--   
-- -- Example: scanl (+) 0 <1,2,3,4> = <0,1,3,6,10> scanl :: (SVECTOR ty a, SVECTOR ty b) => (a -> b -> a) -> a -> Vector ty b -> Vector ty a -- | O(n) Haskell-style scan with strict accumulator scanl' :: (SVECTOR ty a, SVECTOR ty b) => (a -> b -> a) -> a -> Vector ty b -> Vector ty a -- | O(n) Scan over a non-empty vector -- --
--   scanl f <x1,...,xn> = <y1,...,yn>
--     where y1 = x1
--           yi = f y(i-1) xi
--   
scanl1 :: SVECTOR ty a => (a -> a -> a) -> Vector ty a -> Vector ty a -- | O(n) Scan over a non-empty vector with a strict accumulator scanl1' :: SVECTOR ty a => (a -> a -> a) -> Vector ty a -> Vector ty a -- | O(n) Right-to-left prescan -- --
--   prescanr f z = reverse . prescanl (flip f) z . reverse
--   
prescanr :: (SVECTOR ty a, SVECTOR ty b) => (a -> b -> b) -> b -> Vector ty a -> Vector ty b -- | O(n) Right-to-left prescan with strict accumulator prescanr' :: (SVECTOR ty a, SVECTOR ty b) => (a -> b -> b) -> b -> Vector ty a -> Vector ty b -- | O(n) Right-to-left scan postscanr :: (SVECTOR ty a, SVECTOR ty b) => (a -> b -> b) -> b -> Vector ty a -> Vector ty b -- | O(n) Right-to-left scan with strict accumulator postscanr' :: (SVECTOR ty a, SVECTOR ty b) => (a -> b -> b) -> b -> Vector ty a -> Vector ty b -- | O(n) Right-to-left Haskell-style scan scanr :: (SVECTOR ty a, SVECTOR ty b) => (a -> b -> b) -> b -> Vector ty a -> Vector ty b -- | O(n) Right-to-left Haskell-style scan with strict accumulator scanr' :: (SVECTOR ty a, SVECTOR ty b) => (a -> b -> b) -> b -> Vector ty a -> Vector ty b -- | O(n) Right-to-left scan over a non-empty vector scanr1 :: SVECTOR ty a => (a -> a -> a) -> Vector ty a -> Vector ty a -- | O(n) Right-to-left scan over a non-empty vector with a strict -- accumulator scanr1' :: SVECTOR ty a => (a -> a -> a) -> Vector ty a -> Vector ty a -- | O(n) Convert a vector to a list toList :: SVECTOR ty a => Vector ty a -> [a] -- | O(n) Convert a list to a vector fromList :: forall ty a. SVECTOR ty a => [a] -> Vector ty a -- | O(n) Convert the first n elements of a list to a -- vector -- --
--   fromListN n xs = fromList (take n xs)
--   
fromListN :: forall ty a. SVECTOR ty a => Int -> [a] -> Vector ty a -- | O(n) Yield an immutable copy of the mutable vector. freeze :: (MonadR m, VECTOR (Region m) ty a, ElemRep V ty ~ a) => MVector (Region m) ty a -> m (Vector ty a) -- | O(n) Yield a mutable copy of the immutable vector. thaw :: (MonadR m, VECTOR (Region m) ty a, ElemRep V ty ~ a) => Vector ty a -> m (MVector (Region m) ty a) -- | O(n) Copy an immutable vector into a mutable one. The two -- vectors must have the same length. copy :: (MonadR m, VECTOR (Region m) ty a, ElemRep V ty ~ a) => MVector (Region m) ty a -> Vector ty a -> m () -- | O(1) Unsafe convert a mutable vector to an immutable one with -- copying. The mutable vector may not be used after this operation. unsafeFreeze :: (VECTOR (Region m) ty a, MonadR m, ElemRep V ty ~ a) => MVector (Region m) ty a -> m (Vector ty a) -- | O(1) Unsafely convert an immutable vector to a mutable one with -- copying. The immutable vector may not be used after this operation. unsafeThaw :: (MonadR m, VECTOR (Region m) ty a, ElemRep V ty ~ a) => Vector ty a -> m (MVector (Region m) ty a) -- | O(n) Copy an immutable vector into a mutable one. The two -- vectors must have the same length. This is not checked. unsafeCopy :: (MonadR m, VECTOR (Region m) ty a, ElemRep V ty ~ a) => MVector (Region m) ty a -> Vector ty a -> m () -- | O(n) Convert a character vector into a String. toString :: Vector 'Char Word8 -> String -- | O(n) Convert a character vector into a strict -- ByteString. toByteString :: Vector 'Char Word8 -> ByteString -- | This function is unsafe and ByteString should not be used outside of -- the function. Any change to bytestring will be reflected in the source -- vector, thus breaking referencial transparancy. unsafeWithByteString :: NFData a => Vector 'Char Word8 -> (ByteString -> IO a) -> a instance (Data.Reflection.Reifies t (Control.Monad.R.Internal.AcquireIO s), Data.Vector.SEXP.Base.SVECTOR ty a) => Data.Vector.Generic.Base.Vector (Data.Vector.SEXP.W t ty) a instance (GHC.Classes.Eq a, Data.Vector.SEXP.Base.SVECTOR ty a) => GHC.Classes.Eq (Data.Vector.SEXP.Vector ty a) instance (GHC.Show.Show a, Data.Vector.SEXP.Base.SVECTOR ty a) => GHC.Show.Show (Data.Vector.SEXP.Vector ty a) instance Data.Vector.SEXP.Base.SVECTOR ty a => GHC.Exts.IsList (Data.Vector.SEXP.Vector ty a) -- | Facilities to get Haskell's garbage collector to manage the liveness -- of values allocated on the R heap. By default, R values remain live so -- long as the current region is extant. The R garbage collector may only -- free them after the end of the region. Sometimes, this discipline -- incurs too high of a memory usage and nested regions are not always a -- solution. -- -- This module enables registering a callback with the GHC garbage -- collector. In this way, when the GHC garbage collector detects that a -- value is no longer live, we can notify the R garbage collector of this -- fact. The R garbage collector is then free to deallocate the memory -- associated with the value soon after that. -- -- This module hence offers an alternative, more flexible memory -- management discipline, at a performance cost. In particular, -- collections of many small, short-lived objects are best managed using -- regions. module Language.R.GC -- | Declare memory management for this value to be automatic. That is, the -- memory associated with it may be freed as soon as the garbage -- collector notices that it is safe to do so. -- -- Values with automatic memory management are tagged with the global -- region. The reason is that just like for other global values, -- deallocation of the value can never be observed. Indeed, it is a mere -- "optimization" to deallocate the value sooner - it would still be -- semantically correct to never deallocate it at all. automatic :: MonadR m => SEXP s a -> m (SEXP G a) -- | automatic for SomeSEXP. automaticSome :: MonadR m => SomeSEXP s -> m (SomeSEXP G) -- | Global variables used by the R interpreter. All are constant, but the -- values of some of them may change over time (e.g. the global -- environment). module Language.R.Globals -- | The base environment. baseEnv :: SEXP G 'Env -- | The empty environment. emptyEnv :: SEXP G 'Env -- | The global environment. globalEnv :: SEXP G 'Env -- | R's NULL value. nilValue :: SEXP G 'Nil -- | Value substituted for all missing actual arguments of a function call. missingArg :: SEXP G 'Symbol -- | Special value to which all symbols unbound in the current environment -- resolve to. unboundValue :: SEXP G 'Symbol isRInteractive :: Ptr CInt signalHandlersPtr :: Ptr CInt inputHandlers :: Ptr InputHandler pokeRVariables :: RVariables -> IO () -- | Helper module for writing event loops that mesh with R events. -- -- Events in R are dispatched from a number of file descriptors. The R -- runtime maintains a list of "input handlers", essentially a set of -- file descriptors together with callbacks for each one, invoked -- whenever the file descriptor becomes available for reading. This -- module exports functions for dispatching on both R events and Haskell -- events simultaneously, using GHC.Event, which is based on -- epollkqueuepoll under the hood for efficient and scalable event -- dispatching. -- -- Event dispatching and processing is in particular necessary for R's -- GUI to be responsive. For a consistent user experience, you should -- arrange for all GUI related events to be dispatched from a single -- thread, ideally the program's main thread. In fact on some platforms, -- most notably OS X (darwin), you must use the main thread. -- -- Event loops can be constructed in one of two ways: -- --
    --
  1. eventLoopPoll, which uses GHC's poll(2) (and -- related syscalls) based efficient and scalable mechanisms for event -- dispatch;
  2. --
  3. eventLoopSelect, which uses R's select(2) based -- mechasism.
  4. --
-- -- NOTE: in GHC 7.8 and 7.10, eventLoopPoll is currently -- unusable, due to a number of functions from the event API not being -- exported like they were previously. module Language.R.Event -- | Iterate over each input handler in a chain. forIH :: Ptr InputHandler -> (InputHandler -> IO a) -> IO [a] -- | Variant of forIH that throws away the result. forIH_ :: Ptr InputHandler -> (InputHandler -> IO ()) -> IO () -- | Register all R input handlers with the given event manager. Set an -- alarm to process polled events if R_wait_usec is non-zero. -- Returns keys useful for unregistering input handlers. registerREvents :: MonadR m => EventManager -> m ([FdKey], Maybe TimeoutKey) -- | Process events in a loop. Uses a new GHC event manager under the hood. -- This function should be called from the main thread. It never returns. -- -- Currently unimplemented. eventLoopPoll :: MonadR m => m () -- | Process events in a loop. Uses R's select() mechanism under -- the hood. This function should be called from the main thread. It -- never returns. eventLoopSelect :: MonadR m => m () -- | Manually trigger processing all pending events. Useful when at an -- interactive prompt and no event loop is running. refresh :: MonadR m => m () -- | Provides a shallow view of a SEXP R value as an -- algebraic datatype. This is useful to define functions over R values -- in Haskell with pattern matching. For example: -- --
--   toPair :: SEXP a -> (SomeSEXP, SomeSEXP)
--   toPair (hexp -> List _ (Just car) (Just cdr)) = (SomeSEXP car, SomeSEXP cdr)
--   toPair (hexp -> Lang car (Just cdr)) = (SomeSEXP car, SomeSEXP cdr)
--   toPair s = error $ "Cannot extract pair from object of type " ++ typeOf s
--   
-- -- (See SomeSEXP for why we need to use it here.) -- -- The view is said to be shallow because it only unfolds the -- head of the R value into an algebraic datatype. In this way, functions -- producing views can be written non-recursively, hence inlined at all -- call sites and simplified away. When produced by a view function in a -- pattern match, allocation of the view can be compiled away and hence -- producing a view can be done at no runtime cost. In fact, pattern -- matching on a view in this way is more efficient than using the -- accessor functions defined in Foreign.R, because we avoid the -- overhead of calling one or more FFI functions entirely. -- -- HExp is the view and hexp is the view -- function that projects SEXPs into HExp views. module Language.R.HExp -- | A view of R's internal SEXP structure as an algebraic datatype. -- Because this is in fact a GADT, the use of named record fields is not -- possible here. Named record fields give rise to functions for whom it -- is not possible to assign a reasonable type (existentially quantified -- type variables would escape). -- -- See -- https://cran.r-project.org/doc/manuals/r-release/R-ints.html#SEXPTYPEs. data HExp :: * -> SEXPTYPE -> * -- | The NULL value (NILSXP). [Nil] :: HExp s 'Nil -- | A symbol (SYMSXP). [Symbol] :: a :∈ ['Char, 'Nil] => SEXP s a -> SEXP s b -> SEXP s c -> HExp s 'Symbol -- | A list (LISTSXP). [List] :: (IsPairList b, c :∈ ['Symbol, 'Nil]) => SEXP s a -> SEXP s b -> SEXP s c -> HExp s 'List -- | An environment (ENVSXP). [Env] :: (IsPairList a, b :∈ ['Env, 'Nil], c :∈ ['Vector, 'Nil]) => SEXP s a -> SEXP s b -> SEXP s c -> HExp s 'Env -- | A closure (CLOSXP). [Closure] :: IsPairList a => SEXP s a -> SEXP s b -> SEXP s 'Env -> HExp s 'Closure -- | A promise (PROMSXP). [Promise] :: (IsExpression b, c :∈ ['Env, 'Nil]) => SEXP s a -> SEXP s b -> SEXP s c -> HExp s 'Promise -- | Language objects (LANGSXP) are calls (including formulae and -- so on). Internally they are pairlists with first element a reference -- to the function to be called with remaining elements the actual -- arguments for the call (and with the tags if present giving the -- specified argument names). Although this is not enforced, many places -- in the R code assume that the pairlist is of length one or more, often -- without checking. [Lang] :: (IsExpression a, IsPairList b) => SEXP s a -> SEXP s b -> HExp s 'Lang -- | A special (built-in) function call (SPECIALSXP). It carries -- an offset into the table of primitives but for our purposes is opaque. [Special] :: HExp s 'Special -- | A BUILTINSXP. This is similar to Special, except the -- arguments to a Builtin are always evaluated. [Builtin] :: HExp s 'Builtin -- | An internal character string (CHARSXP). [Char] :: {-# UNPACK #-} !Vector 'Char Word8 -> HExp s 'Char -- | A logical vector (LGLSXP). [Logical] :: {-# UNPACK #-} !Vector 'Logical Logical -> HExp s 'Logical -- | An integer vector (INTSXP). [Int] :: {-# UNPACK #-} !Vector 'Int Int32 -> HExp s 'Int -- | A numeric vector (REALSXP). [Real] :: {-# UNPACK #-} !Vector 'Real Double -> HExp s 'Real -- | A complex vector (CPLXSXP). [Complex] :: {-# UNPACK #-} !Vector 'Complex (Complex Double) -> HExp s 'Complex -- | A character vector (STRSXP). [String] :: {-# UNPACK #-} !Vector 'String (SEXP V 'Char) -> HExp s 'String -- | A special type of LISTSXP for the value bound to a -- ... symbol [DotDotDot] :: IsPairList a => SEXP s a -> HExp s 'List -- | A list/generic vector (VECSXP). [Vector] :: {-# UNPACK #-} !Int32 -> {-# UNPACK #-} !Vector 'Vector (SomeSEXP V) -> HExp s 'Vector -- | An expression vector (EXPRSXP). [Expr] :: {-# UNPACK #-} !Int32 -> {-# UNPACK #-} !Vector 'Expr (SomeSEXP V) -> HExp s 'Expr -- | A ‘byte-code’ object generated by R (BCODESXP). [Bytecode] :: HExp s 'Bytecode -- | An external pointer (EXTPTRSXP) [ExtPtr] :: c :∈ ['Symbol, 'Nil] => Ptr () -> SEXP s b -> SEXP s c -> HExp s 'ExtPtr -- | A weak reference (WEAKREFSXP). [WeakRef] :: (a :∈ ['Env, 'ExtPtr, 'Nil], c :∈ ['Closure, 'Builtin, 'Special, 'Nil], d :∈ ['WeakRef, 'Nil]) => SEXP s a -> SEXP s b -> SEXP s c -> SEXP s d -> HExp s 'WeakRef -- | A raw vector (RAWSXP). [Raw] :: {-# UNPACK #-} !Vector 'Raw Word8 -> HExp s 'Raw -- | An S4 class which does not consist solely of a simple type such as an -- atomic vector or function (S4SXP). [S4] :: a :∈ ['Symbol, 'Nil] => SEXP s a -> HExp s 'S4 -- | Heterogeneous equality. (===) :: TestEquality f => f a -> f b -> Bool -- | A view function projecting a view of SEXP as an algebraic -- datatype, that can be analyzed through pattern matching. hexp :: SEXP s a -> HExp s a -- | Project the vector out of SEXPs. vector :: IsVector a => SEXP s a -> Vector a (ElemRep V a) instance Data.Type.Equality.TestEquality (Language.R.HExp.E s) instance Data.Type.Equality.TestEquality (Language.R.HExp.HExp s) instance GHC.Classes.Eq (Language.R.HExp.HExp s a) -- | Debugging facilities, in particular to analyze the internal structure -- of a SEXP as structured JSON. -- -- This module is intended to be imported qualified. module Language.R.Debug inspect :: SEXP s a -> String instance Data.Aeson.Types.ToJSON.ToJSON Foreign.R.Type.SEXPTYPE instance Data.Aeson.Types.ToJSON.ToJSON Foreign.R.Internal.SEXPInfo instance Data.Aeson.Types.ToJSON.ToJSON a => Data.Aeson.Types.ToJSON.ToJSON (Data.Complex.Complex a) instance Data.Aeson.Types.ToJSON.ToJSON (Foreign.R.Internal.SEXP s a) instance Data.Aeson.Types.ToJSON.ToJSON (Foreign.R.Internal.SomeSEXP s) -- | 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. module Language.R.Instance -- | 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. data R s a -- | 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). -- -- throws Error. Generaly any R function may throw -- RError that is safe to be cached and computation can proceed. -- However RError will cancel entire R block. So in order to -- catch exception in more fine grained way one has to use function -- tryCatch inside R block. runRegion :: NFData a => (forall s. R s a) -> IO a unsafeRunRegion :: NFData a => R s a -> IO a -- | Configuration options for the R runtime. Configurations form monoids, -- so arguments can be accumulated left-to-right through monoidal -- composition. data Config Config :: Last String -> [String] -> Last Bool -> Config -- | Program name. If Nothing then the value of getProgName -- will be used. [configProgName] :: Config -> Last String -- | Command-line arguments. [configArgs] :: Config -> [String] -- | Set to True if you're happy to let R install its own signal -- handlers during initialization. By default R sets following signal -- handlers: -- -- [configSignalHandlers] :: Config -> Last Bool -- | Default argument to pass to initialize. defaultConfig :: Config -- | 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). withEmbeddedR :: Config -> IO a -> IO a -- | 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. initialize :: Config -> IO () -- | Finalize an R instance. finalize :: IO () instance Control.Monad.Catch.MonadThrow (Language.R.Instance.R s) instance Control.Monad.Catch.MonadMask (Language.R.Instance.R s) instance Control.Monad.Catch.MonadCatch (Language.R.Instance.R s) instance Control.Monad.IO.Class.MonadIO (Language.R.Instance.R s) instance GHC.Base.Monad (Language.R.Instance.R s) instance GHC.Base.Functor (Language.R.Instance.R s) instance GHC.Base.Applicative (Language.R.Instance.R s) instance Data.Default.Class.Default Language.R.Instance.Config instance GHC.Base.Semigroup Language.R.Instance.Config instance GHC.Base.Monoid Language.R.Instance.Config instance Control.Monad.Fail.MonadFail (Language.R.Instance.R s) instance Control.Monad.Primitive.PrimMonad (Language.R.Instance.R s) instance Control.Monad.R.Class.MonadR (Language.R.Instance.R s) module Language.R.Internal.FunWrappers.TH -- | Generate wrappers from n to m. thWrappers :: Int -> Int -> Q [Dec] -- | Generate wrapper. -- -- Example for input 5: -- --
--   foreign import ccall "wrapper" wrap5
--      :: (  SEXP a -> SEXP b -> SEXP c
--         -> SEXP d -> SEXP e -> IO (SEXP f)
--         )
--      -> IO (FunPtr (  SEXP a -> SEXP b -> SEXP c
--                    -> SEXP d -> SEXP e -> IO (SEXP f)
--                    )
--            )
--   
thWrapper :: Int -> Q Dec -- | Generate Literal Instance for wrapper. -- -- Example for input 6: instance ( Literal a a0, Literal b b0, -- Literal c c0, Literal d d0, Literal e e0 , Literal f f0, Literal g g0 -- ) => Literal (a -> b -> c -> d -> e -> f -> IO g) -- R.ExtPtr where mkSEXP = funToSEXP wrap6 fromSEXP = error -- "Unimplemented." thWrapperLiteral :: Int -> Q Dec thWrapperLiterals :: Int -> Int -> Q [Dec] -- | Helpers for passing functions pointers between Haskell and R. module Language.R.Internal.FunWrappers wrap0 :: IO SEXP0 -> IO (FunPtr (IO SEXP0)) wrap1 :: (SEXP0 -> IO SEXP0) -> IO (FunPtr (SEXP0 -> IO SEXP0)) wrap2 :: (SEXP0 -> SEXP0 -> IO SEXP0) -> IO (FunPtr (SEXP0 -> SEXP0 -> IO SEXP0)) wrap3 :: (SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0) -> IO (FunPtr (SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0)) wrap12 :: (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0) -> IO (FunPtr (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0)) wrap11 :: (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0) -> IO (FunPtr (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0)) wrap10 :: (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0) -> IO (FunPtr (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0)) wrap9 :: (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0) -> IO (FunPtr (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0)) wrap8 :: (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0) -> IO (FunPtr (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0)) wrap7 :: (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0) -> IO (FunPtr (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0)) wrap6 :: (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0) -> IO (FunPtr (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0)) wrap5 :: (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0) -> IO (FunPtr (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0)) wrap4 :: (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0) -> IO (FunPtr (SEXP0 -> SEXP0 -> SEXP0 -> SEXP0 -> IO SEXP0)) module Language.R.Literal -- | Values that can be converted to SEXP. class SingI ty => Literal a ty | a -> ty -- | Internal function for converting a literal to a SEXP value. You -- probably want to be using mkSEXP instead. mkSEXPIO :: Literal a ty => a -> IO (SEXP V ty) fromSEXP :: Literal a ty => SEXP s ty -> a -- | Internal function for converting a literal to a SEXP value. You -- probably want to be using mkSEXP instead. mkSEXPIO :: (Literal a ty, IsVector ty, Literal [a] ty) => a -> IO (SEXP V ty) fromSEXP :: (Literal a ty, IsVector ty, Literal [a] ty) => SEXP s ty -> a -- | Create a pairlist from an association list. Result is either a -- pairlist or nilValue if the input is the null list. These are -- two distinct forms. Hence why the type of this function is not more -- precise. toPairList :: MonadR m => [(String, SomeSEXP (Region m))] -> m (SomeSEXP (Region m)) -- | Create an association list from a pairlist. R Pairlists are -- nil-terminated chains of nested cons cells, as in LISP. fromPairList :: SomeSEXP s -> [(String, SomeSEXP s)] -- | Like fromSEXP, but with no static type satefy. Performs a -- dynamic (i.e. at runtime) check instead. fromSomeSEXP :: forall s a form. Literal a form => SomeSEXP s -> a -- | Create a SEXP value and protect it in current region mkSEXP :: (Literal a b, MonadR m) => a -> m (SEXP (Region m) b) -- | Like fromSomeSEXP, but behaves like the as.* family of -- functions in R, by performing a best effort conversion to the target -- form (e.g. rounds reals to integers, etc) for atomic types. dynSEXP :: forall a s ty. Literal a ty => SomeSEXP s -> a mkSEXPVector :: (Storable (ElemRep s a), IsVector a) => SSEXPTYPE a -> [IO (ElemRep s a)] -> SEXP s a mkSEXPVectorIO :: (Storable (ElemRep s a), IsVector a) => SSEXPTYPE a -> [IO (ElemRep s a)] -> IO (SEXP s a) mkProtectedSEXPVector :: IsVector b => SSEXPTYPE b -> [SEXP s a] -> SEXP s b mkProtectedSEXPVectorIO :: IsVector b => SSEXPTYPE b -> [SEXP s a] -> IO (SEXP s b) funToSEXP :: HFunWrap a b => (b -> IO (FunPtr b)) -> a -> IO (SEXP s 'ExtPtr) instance (Control.DeepSeq.NFData a1, Language.R.Literal.Literal a2 i1, Language.R.Literal.Literal a3 i2, Language.R.Literal.Literal a4 i3, Language.R.Literal.Literal a1 i4) => Language.R.Literal.Literal (a2 -> a3 -> a4 -> Language.R.Instance.R s a1) 'Foreign.R.Type.ExtPtr instance (Control.DeepSeq.NFData a1, Language.R.Literal.Literal a2 i1, Language.R.Literal.Literal a3 i2, Language.R.Literal.Literal a4 i3, Language.R.Literal.Literal a5 i4, Language.R.Literal.Literal a1 i5) => Language.R.Literal.Literal (a2 -> a3 -> a4 -> a5 -> Language.R.Instance.R s a1) 'Foreign.R.Type.ExtPtr instance (Control.DeepSeq.NFData a1, Language.R.Literal.Literal a2 i1, Language.R.Literal.Literal a3 i2, Language.R.Literal.Literal a4 i3, Language.R.Literal.Literal a5 i4, Language.R.Literal.Literal a6 i5, Language.R.Literal.Literal a1 i6) => Language.R.Literal.Literal (a2 -> a3 -> a4 -> a5 -> a6 -> Language.R.Instance.R s a1) 'Foreign.R.Type.ExtPtr instance (Control.DeepSeq.NFData a1, Language.R.Literal.Literal a2 i1, Language.R.Literal.Literal a3 i2, Language.R.Literal.Literal a4 i3, Language.R.Literal.Literal a5 i4, Language.R.Literal.Literal a6 i5, Language.R.Literal.Literal a7 i6, Language.R.Literal.Literal a1 i7) => Language.R.Literal.Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> Language.R.Instance.R s a1) 'Foreign.R.Type.ExtPtr instance (Control.DeepSeq.NFData a1, Language.R.Literal.Literal a2 i1, Language.R.Literal.Literal a3 i2, Language.R.Literal.Literal a4 i3, Language.R.Literal.Literal a5 i4, Language.R.Literal.Literal a6 i5, Language.R.Literal.Literal a7 i6, Language.R.Literal.Literal a8 i7, Language.R.Literal.Literal a1 i8) => Language.R.Literal.Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> Language.R.Instance.R s a1) 'Foreign.R.Type.ExtPtr instance (Control.DeepSeq.NFData a1, Language.R.Literal.Literal a2 i1, Language.R.Literal.Literal a3 i2, Language.R.Literal.Literal a4 i3, Language.R.Literal.Literal a5 i4, Language.R.Literal.Literal a6 i5, Language.R.Literal.Literal a7 i6, Language.R.Literal.Literal a8 i7, Language.R.Literal.Literal a9 i8, Language.R.Literal.Literal a1 i9) => Language.R.Literal.Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> Language.R.Instance.R s a1) 'Foreign.R.Type.ExtPtr instance (Control.DeepSeq.NFData a1, Language.R.Literal.Literal a2 i1, Language.R.Literal.Literal a3 i2, Language.R.Literal.Literal a4 i3, Language.R.Literal.Literal a5 i4, Language.R.Literal.Literal a6 i5, Language.R.Literal.Literal a7 i6, Language.R.Literal.Literal a8 i7, Language.R.Literal.Literal a9 i8, Language.R.Literal.Literal a10 i9, Language.R.Literal.Literal a1 i10) => Language.R.Literal.Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> a10 -> Language.R.Instance.R s a1) 'Foreign.R.Type.ExtPtr instance (Control.DeepSeq.NFData a1, Language.R.Literal.Literal a2 i1, Language.R.Literal.Literal a3 i2, Language.R.Literal.Literal a4 i3, Language.R.Literal.Literal a5 i4, Language.R.Literal.Literal a6 i5, Language.R.Literal.Literal a7 i6, Language.R.Literal.Literal a8 i7, Language.R.Literal.Literal a9 i8, Language.R.Literal.Literal a10 i9, Language.R.Literal.Literal a11 i10, Language.R.Literal.Literal a1 i11) => Language.R.Literal.Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> a10 -> a11 -> Language.R.Instance.R s a1) 'Foreign.R.Type.ExtPtr instance (Control.DeepSeq.NFData a1, Language.R.Literal.Literal a2 i1, Language.R.Literal.Literal a3 i2, Language.R.Literal.Literal a4 i3, Language.R.Literal.Literal a5 i4, Language.R.Literal.Literal a6 i5, Language.R.Literal.Literal a7 i6, Language.R.Literal.Literal a8 i7, Language.R.Literal.Literal a9 i8, Language.R.Literal.Literal a10 i9, Language.R.Literal.Literal a11 i10, Language.R.Literal.Literal a12 i11, Language.R.Literal.Literal a1 i12) => Language.R.Literal.Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> a10 -> a11 -> a12 -> Language.R.Instance.R s a1) 'Foreign.R.Type.ExtPtr instance (Control.DeepSeq.NFData a1, Language.R.Literal.Literal a2 i1, Language.R.Literal.Literal a3 i2, Language.R.Literal.Literal a4 i3, Language.R.Literal.Literal a5 i4, Language.R.Literal.Literal a6 i5, Language.R.Literal.Literal a7 i6, Language.R.Literal.Literal a8 i7, Language.R.Literal.Literal a9 i8, Language.R.Literal.Literal a10 i9, Language.R.Literal.Literal a11 i10, Language.R.Literal.Literal a12 i11, Language.R.Literal.Literal a13 i12, Language.R.Literal.Literal a1 i13) => Language.R.Literal.Literal (a2 -> a3 -> a4 -> a5 -> a6 -> a7 -> a8 -> a9 -> a10 -> a11 -> a12 -> a13 -> Language.R.Instance.R s a1) 'Foreign.R.Type.ExtPtr instance (Control.DeepSeq.NFData a, Language.R.Literal.Literal a la) => Language.R.Literal.HFunWrap (Language.R.Instance.R s a) (GHC.Types.IO Foreign.R.Context.SEXP0) instance (Language.R.Literal.Literal a la, Language.R.Literal.HFunWrap b wb) => Language.R.Literal.HFunWrap (a -> b) (Foreign.R.Context.SEXP0 -> wb) instance Language.R.Literal.Literal [Foreign.R.Context.Logical] 'Foreign.R.Type.Logical instance Language.R.Literal.Literal [GHC.Int.Int32] 'Foreign.R.Type.Int instance Language.R.Literal.Literal [GHC.Types.Double] 'Foreign.R.Type.Real instance Language.R.Literal.Literal [Data.Complex.Complex GHC.Types.Double] 'Foreign.R.Type.Complex instance Language.R.Literal.Literal [GHC.Base.String] 'Foreign.R.Type.String instance Language.R.Literal.Literal Data.Text.Internal.Text 'Foreign.R.Type.String instance Language.R.Literal.Literal Foreign.R.Context.Logical 'Foreign.R.Type.Logical instance Language.R.Literal.Literal GHC.Int.Int32 'Foreign.R.Type.Int instance Language.R.Literal.Literal GHC.Types.Double 'Foreign.R.Type.Real instance Language.R.Literal.Literal (Data.Complex.Complex GHC.Types.Double) 'Foreign.R.Type.Complex instance Language.R.Literal.Literal GHC.Base.String 'Foreign.R.Type.String instance Data.Vector.SEXP.Base.SVECTOR ty a => Language.R.Literal.Literal (Data.Vector.SEXP.Vector ty a) ty instance Data.Vector.SEXP.Base.VECTOR Control.Memory.Region.V ty a => Language.R.Literal.Literal (Data.Vector.SEXP.Mutable.Internal.MVector Control.Memory.Region.V ty a) ty instance Data.Singletons.SingI a => Language.R.Literal.Literal (Foreign.R.Internal.SEXP s a) a instance Language.R.Literal.Literal (Foreign.R.Internal.SomeSEXP s) 'Foreign.R.Type.Any instance (Control.DeepSeq.NFData a, Language.R.Literal.Literal a b) => Language.R.Literal.Literal (Language.R.Instance.R s a) 'Foreign.R.Type.ExtPtr instance (Control.DeepSeq.NFData b, Language.R.Literal.Literal a a0, Language.R.Literal.Literal b b0) => Language.R.Literal.Literal (a -> Language.R.Instance.R s b) 'Foreign.R.Type.ExtPtr instance (Control.DeepSeq.NFData c, Language.R.Literal.Literal a a0, Language.R.Literal.Literal b b0, Language.R.Literal.Literal c c0) => Language.R.Literal.Literal (a -> b -> Language.R.Instance.R s c) 'Foreign.R.Type.ExtPtr module Language.R.Internal -- | Call a pure unary R function of the given name in the global -- environment. r1 :: ByteString -> SEXP s a -> IO (SomeSEXP V) -- | Call a pure binary R function. See r1 for additional comments. r2 :: ByteString -> SEXP s a -> SEXP s b -> IO (SomeSEXP V) -- | Internalize a symbol name. installIO :: String -> IO (SEXP V 'Symbol) -- | Wrappers for low-level R functions. module Language.R -- | A SEXP of unknown form. data SomeSEXP s SomeSEXP :: {-# UNPACK #-} !SEXP s a -> SomeSEXP s -- | The basic type of all R expressions, classified by the form of the -- expression, and the memory region in which it has been allocated. data SEXP s (a :: SEXPTYPE) -- | Deconstruct a SomeSEXP. Takes a continuation since otherwise -- the existentially quantified variable hidden inside SomeSEXP -- would escape. unSomeSEXP :: SomeSEXP s -> (forall a. SEXP s a -> r) -> r -- | Return the "type" tag (aka the form tag) of the given SEXP. -- This function is pure because the type of an object does not normally -- change over the lifetime of the object. typeOf :: SEXP s a -> SEXPTYPE -- | Cast the type of a SEXP into another type. This function is -- partial: at runtime, an error is raised if the source form tag does -- not match the target form tag. cast :: SSEXPTYPE a -> SomeSEXP s -> SEXP s a -- | Cast form of first argument to that of the second argument. asTypeOf :: SomeSEXP s -> SEXP s a -> SEXP s a -- | Unsafe coercion from one form to another. This is unsafe, in the sense -- that using this function improperly could cause code to crash in -- unpredictable ways. Contrary to cast, it has no runtime cost -- since it does not introduce any dynamic check at runtime. unsafeCoerce :: SEXP s a -> SEXP s b -- | Evaluate a (sequence of) expression(s) in the global environment. eval :: MonadR m => SEXP s a -> m (SomeSEXP (Region m)) -- | Silent version of eval function that discards it's result. eval_ :: MonadR m => SEXP s a -> m () -- | Evaluate a (sequence of) expression(s) in the given environment, -- returning the value of the last. evalEnv :: MonadR m => SEXP s a -> SEXP s 'Env -> m (SomeSEXP (Region m)) -- | Internalize a symbol name. install :: MonadR m => String -> m (SEXP V 'Symbol) -- | Cancel any ongoing R computation in the current process. After -- interruption an RError exception will be raised. -- -- This call is safe to run in any thread. If there is no R computation -- running, the next computaion will be immediately cancelled. Note that -- R will only interrupt computations at so-called "safe points" (in -- particular, not in the middle of a C call). cancel :: IO () -- | Throw an R error as an exception. throwR :: MonadR m => SEXP s 'Env -> m a -- | Throw an R exception with specified message. throwRMessage :: MonadR m => String -> m a -- | Parse file and perform some actions on parsed file. -- -- This function uses continuation because this is an easy way to make -- operations GC-safe. -- | Deprecated: Use [r| parse(file="pathtofile") |] instead. parseFile :: FilePath -> (SEXP s 'Expr -> IO a) -> IO a -- | Deprecated: Use [r| parse(text=...) |] instead. parseText :: String -> Bool -> IO (SEXP V 'Expr) -- | Create an R character string from a Haskell string. -- | Deprecated: Use mkSEXP instead string :: String -> IO (SEXP V 'Char) -- | Create an R string vector from a Haskell string. -- | Deprecated: Use mkSEXP instead strings :: String -> IO (SEXP V 'String) module Language.R.QQ -- | An R value, expressed as an R expression, in R's syntax. r :: QuasiQuoter -- | Quasiquoter for pure R code (no side effects) and that does not depend -- on the global environment (referential transparency). This means that -- all symbols must appear qualified with a package namespace (whose -- bindings are locked by default), the code must not affect R shared -- state in any way, including the global environment, and must not -- perform I/O. rsafe :: QuasiQuoter -- | Map backwards slashes to forward slashes. -- -- Find all occurences of antiquotations. -- -- This function works by parsing the user's R code in a separate R -- process. As a nice side-effect, it will detect and return any syntax -- errors in the quasi-quoted R code. -- -- This function is exposed only for testing; you probably don't need to -- call it in the user code. collectAntis :: String -> IO (Either String [String]) -- | | Copyright: (C) 2013 Amgen, Inc. -- -- DEPRECATED: use Language.R instead. module H.Prelude -- | The class of R interaction monads. For safety, in compiled code we -- normally use the R monad. For convenience, in a GHCi session, -- we normally use the IO monad directly (by means of a -- MonadR instance for IO, imported only in GHCi). class (Applicative m, MonadIO m, MonadCatch m, MonadMask m, PrimMonad m) => MonadR m where { -- | A reification of an R execution context, i.e. a "session". data ExecContext m :: *; } -- | Lift an IO action. io :: MonadR m => IO a -> m a -- | Acquire ownership in the current region of the given object. This -- means that the liveness of the object is guaranteed so long as the -- current region remains active (the R garbage collector will not -- attempt to free it). acquire :: (MonadR m, s ~ V) => SEXP s a -> m (SEXP (Region m) a) -- | Acquire ownership in the current region of the given object. This -- means that the liveness of the object is guaranteed so long as the -- current region remains active (the R garbage collector will not -- attempt to free it). acquire :: (MonadR m, MonadIO m, Region m ~ G) => SEXP s a -> m (SEXP (Region m) a) -- | Get the current execution context. getExecContext :: MonadR m => m (ExecContext m) -- | Provides no static guarantees that resources do not extrude the scope -- of their region. Acquired resources are not freed automatically upon -- exit. For internal use only. unsafeRunWithExecContext :: MonadR m => m a -> ExecContext m -> IO a type Region m = PrimState m -- | acquire for SomeSEXP. acquireSome :: MonadR m => SomeSEXP V -> m (SomeSEXP (Region m)) -- | The singleton kind-indexed type family. type family Sing :: k -> Type -- | R uses three-valued logic. data {-# CTYPE "Logical" #-} Logical FALSE :: Logical TRUE :: Logical NA :: Logical -- | Constraint synonym grouping all expression forms into one class. -- According to R internals, an expression is usually a Lang, but -- can sometimes also be an Expr or a Symbol. type IsExpression (a :: SEXPTYPE) = (SingI a, a :∈ [Lang, Expr, Symbol]) -- | IsPairList a holds iff R's is.pairlist() returns -- TRUE. type IsPairList (a :: SEXPTYPE) = (SingI a, a :∈ [List, Nil]) -- | IsList a holds iff R's is.list() returns -- TRUE. type IsList (a :: SEXPTYPE) = (SingI a, a :∈ 'Char : 'Logical : 'Int : 'Real : 'Complex : 'String : 'Vector : 'Expr : 'WeakRef : 'Raw : List : '[]) -- | Non-atomic vector forms. See src/main/memory.c:SET_VECTOR_ELT -- in the R source distribution. type IsGenericVector (a :: SEXPTYPE) = (SingI a, a :∈ [Vector, Expr, WeakRef]) -- | Constraint synonym grouping all vector forms into one class. -- IsVector a holds iff R's is.vector() returns -- TRUE. type IsVector (a :: SEXPTYPE) = (SingI a, a :∈ 'Char : 'Logical : 'Int : 'Real : 'Complex : 'String : 'Vector : 'Expr : 'WeakRef : 'Raw : '[]) -- | Used where the R documentation speaks of "pairlists", which are really -- just regular lists. type PairList = List data SSEXPTYPE :: SEXPTYPE -> Type [SNil] :: SSEXPTYPE ('Nil :: SEXPTYPE) [SSymbol] :: SSEXPTYPE ('Symbol :: SEXPTYPE) [SList] :: SSEXPTYPE ('List :: SEXPTYPE) [SClosure] :: SSEXPTYPE ('Closure :: SEXPTYPE) [SEnv] :: SSEXPTYPE ('Env :: SEXPTYPE) [SPromise] :: SSEXPTYPE ('Promise :: SEXPTYPE) [SLang] :: SSEXPTYPE ('Lang :: SEXPTYPE) [SSpecial] :: SSEXPTYPE ('Special :: SEXPTYPE) [SBuiltin] :: SSEXPTYPE ('Builtin :: SEXPTYPE) [SChar] :: SSEXPTYPE ('Char :: SEXPTYPE) [SLogical] :: SSEXPTYPE ('Logical :: SEXPTYPE) [SInt] :: SSEXPTYPE ('Int :: SEXPTYPE) [SReal] :: SSEXPTYPE ('Real :: SEXPTYPE) [SComplex] :: SSEXPTYPE ('Complex :: SEXPTYPE) [SString] :: SSEXPTYPE ('String :: SEXPTYPE) [SDotDotDot] :: SSEXPTYPE ('DotDotDot :: SEXPTYPE) [SAny] :: SSEXPTYPE ('Any :: SEXPTYPE) [SVector] :: SSEXPTYPE ('Vector :: SEXPTYPE) [SExpr] :: SSEXPTYPE ('Expr :: SEXPTYPE) [SBytecode] :: SSEXPTYPE ('Bytecode :: SEXPTYPE) [SExtPtr] :: SSEXPTYPE ('ExtPtr :: SEXPTYPE) [SWeakRef] :: SSEXPTYPE ('WeakRef :: SEXPTYPE) [SRaw] :: SSEXPTYPE ('Raw :: SEXPTYPE) [SS4] :: SSEXPTYPE ('S4 :: SEXPTYPE) [SNew] :: SSEXPTYPE ('New :: SEXPTYPE) [SFree] :: SSEXPTYPE ('Free :: SEXPTYPE) [SFun] :: SSEXPTYPE ('Fun :: SEXPTYPE) -- | A SEXP of unknown form. data SomeSEXP s SomeSEXP :: {-# UNPACK #-} !SEXP s a -> SomeSEXP s -- | The basic type of all R expressions, classified by the form of the -- expression, and the memory region in which it has been allocated. data SEXP s (a :: SEXPTYPE) -- | Deconstruct a SomeSEXP. Takes a continuation since otherwise -- the existentially quantified variable hidden inside SomeSEXP -- would escape. unSomeSEXP :: SomeSEXP s -> (forall a. SEXP s a -> r) -> r -- | Return the "type" tag (aka the form tag) of the given SEXP. -- This function is pure because the type of an object does not normally -- change over the lifetime of the object. typeOf :: SEXP s a -> SEXPTYPE -- | Cast the type of a SEXP into another type. This function is -- partial: at runtime, an error is raised if the source form tag does -- not match the target form tag. cast :: SSEXPTYPE a -> SomeSEXP s -> SEXP s a -- | Cast form of first argument to that of the second argument. asTypeOf :: SomeSEXP s -> SEXP s a -> SEXP s a -- | Unsafe coercion from one form to another. This is unsafe, in the sense -- that using this function improperly could cause code to crash in -- unpredictable ways. Contrary to cast, it has no runtime cost -- since it does not introduce any dynamic check at runtime. unsafeCoerce :: SEXP s a -> SEXP s b -- | Declare memory management for this value to be automatic. That is, the -- memory associated with it may be freed as soon as the garbage -- collector notices that it is safe to do so. -- -- Values with automatic memory management are tagged with the global -- region. The reason is that just like for other global values, -- deallocation of the value can never be observed. Indeed, it is a mere -- "optimization" to deallocate the value sooner - it would still be -- semantically correct to never deallocate it at all. automatic :: MonadR m => SEXP s a -> m (SEXP G a) -- | automatic for SomeSEXP. automaticSome :: MonadR m => SomeSEXP s -> m (SomeSEXP G) pokeRVariables :: RVariables -> IO () isRInteractive :: Ptr CInt signalHandlersPtr :: Ptr CInt -- | Special value to which all symbols unbound in the current environment -- resolve to. unboundValue :: SEXP G 'Symbol -- | R's NULL value. nilValue :: SEXP G 'Nil -- | Value substituted for all missing actual arguments of a function call. missingArg :: SEXP G 'Symbol -- | The base environment. baseEnv :: SEXP G 'Env -- | The empty environment. emptyEnv :: SEXP G 'Env -- | The global environment. globalEnv :: SEXP G 'Env inputHandlers :: Ptr InputHandler -- | Configuration options for the R runtime. Configurations form monoids, -- so arguments can be accumulated left-to-right through monoidal -- composition. data Config Config :: Last String -> [String] -> Last Bool -> Config -- | Program name. If Nothing then the value of getProgName -- will be used. [configProgName] :: Config -> Last String -- | Command-line arguments. [configArgs] :: Config -> [String] -- | Set to True if you're happy to let R install its own signal -- handlers during initialization. By default R sets following signal -- handlers: -- -- [configSignalHandlers] :: Config -> Last Bool -- | 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. data R s a -- | 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). withEmbeddedR :: Config -> IO a -> IO a -- | 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). -- -- throws Error. Generaly any R function may throw -- RError that is safe to be cached and computation can proceed. -- However RError will cancel entire R block. So in order to -- catch exception in more fine grained way one has to use function -- tryCatch inside R block. runRegion :: NFData a => (forall s. R s a) -> IO a unsafeRunRegion :: NFData a => R s a -> IO a -- | Default argument to pass to initialize. defaultConfig :: Config -- | 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. initialize :: Config -> IO () -- | Finalize an R instance. finalize :: IO () -- | Values that can be converted to SEXP. class SingI ty => Literal a ty | a -> ty -- | Internal function for converting a literal to a SEXP value. You -- probably want to be using mkSEXP instead. mkSEXPIO :: Literal a ty => a -> IO (SEXP V ty) fromSEXP :: Literal a ty => SEXP s ty -> a -- | Internal function for converting a literal to a SEXP value. You -- probably want to be using mkSEXP instead. mkSEXPIO :: (Literal a ty, IsVector ty, Literal [a] ty) => a -> IO (SEXP V ty) fromSEXP :: (Literal a ty, IsVector ty, Literal [a] ty) => SEXP s ty -> a -- | Create a SEXP value and protect it in current region mkSEXP :: (Literal a b, MonadR m) => a -> m (SEXP (Region m) b) -- | Like fromSEXP, but with no static type satefy. Performs a -- dynamic (i.e. at runtime) check instead. fromSomeSEXP :: forall s a form. Literal a form => SomeSEXP s -> a -- | Like fromSomeSEXP, but behaves like the as.* family of -- functions in R, by performing a best effort conversion to the target -- form (e.g. rounds reals to integers, etc) for atomic types. dynSEXP :: forall a s ty. Literal a ty => SomeSEXP s -> a mkSEXPVector :: (Storable (ElemRep s a), IsVector a) => SSEXPTYPE a -> [IO (ElemRep s a)] -> SEXP s a mkSEXPVectorIO :: (Storable (ElemRep s a), IsVector a) => SSEXPTYPE a -> [IO (ElemRep s a)] -> IO (SEXP s a) mkProtectedSEXPVector :: IsVector b => SSEXPTYPE b -> [SEXP s a] -> SEXP s b mkProtectedSEXPVectorIO :: IsVector b => SSEXPTYPE b -> [SEXP s a] -> IO (SEXP s b) -- | Create a pairlist from an association list. Result is either a -- pairlist or nilValue if the input is the null list. These are -- two distinct forms. Hence why the type of this function is not more -- precise. toPairList :: MonadR m => [(String, SomeSEXP (Region m))] -> m (SomeSEXP (Region m)) -- | Create an association list from a pairlist. R Pairlists are -- nil-terminated chains of nested cons cells, as in LISP. fromPairList :: SomeSEXP s -> [(String, SomeSEXP s)] funToSEXP :: HFunWrap a b => (b -> IO (FunPtr b)) -> a -> IO (SEXP s 'ExtPtr) -- | Parse file and perform some actions on parsed file. -- -- This function uses continuation because this is an easy way to make -- operations GC-safe. -- | Deprecated: Use [r| parse(file="pathtofile") |] instead. parseFile :: FilePath -> (SEXP s 'Expr -> IO a) -> IO a -- | Deprecated: Use [r| parse(text=...) |] instead. parseText :: String -> Bool -> IO (SEXP V 'Expr) -- | Internalize a symbol name. install :: MonadR m => String -> m (SEXP V 'Symbol) -- | Create an R character string from a Haskell string. -- | Deprecated: Use mkSEXP instead string :: String -> IO (SEXP V 'Char) -- | Create an R string vector from a Haskell string. -- | Deprecated: Use mkSEXP instead strings :: String -> IO (SEXP V 'String) -- | Evaluate a (sequence of) expression(s) in the given environment, -- returning the value of the last. evalEnv :: MonadR m => SEXP s a -> SEXP s 'Env -> m (SomeSEXP (Region m)) -- | Evaluate a (sequence of) expression(s) in the global environment. eval :: MonadR m => SEXP s a -> m (SomeSEXP (Region m)) -- | Silent version of eval function that discards it's result. eval_ :: MonadR m => SEXP s a -> m () -- | Throw an R error as an exception. throwR :: MonadR m => SEXP s 'Env -> m a -- | Cancel any ongoing R computation in the current process. After -- interruption an RError exception will be raised. -- -- This call is safe to run in any thread. If there is no R computation -- running, the next computaion will be immediately cancelled. Note that -- R will only interrupt computations at so-called "safe points" (in -- particular, not in the middle of a C call). cancel :: IO () -- | Throw an R exception with specified message. throwRMessage :: MonadR m => String -> m a -- | Manually trigger processing all pending events. Useful when at an -- interactive prompt and no event loop is running. refresh :: MonadR m => m () -- | A Matcher lets you match SEXP values against composable -- patterns, where cascading cases would otherwise be necessary -- otherwise. -- -- Example: -- --
--   -- Check that input is an S3 object of class "matrix"
--   -- and return the value of the "dim" attribute.
--   isMatrix = matchOnly $ do
--      s3 ["matrix"]
--      dim
--   
module Language.R.Matcher -- | A composition of SEXP destructors. A Matcher is bound to -- the region where SomeSEXP is allocated, so extracted value will -- not leak out of the region scope. -- -- This matcher is a pure function, so if you need to allocate any object -- (for example for comparison or lookup) you should do it before running -- matcher. newtype Matcher s a Matcher :: (forall r. SomeSEXP s -> (a -> r) -> (MatcherError s -> r) -> r) -> Matcher s a [runMatcher] :: Matcher s a -> forall r. SomeSEXP s -> (a -> r) -> (MatcherError s -> r) -> r -- | Match a SomeSEXP, returning a MatchError if matching -- failed. -- -- Result is always fully evaluated, since otherwise it wouldn't be -- possible to guarantee that thunks in the return value will not escape -- the memory region. matchOnly :: (MonadR m, NFData a) => Matcher s a -> SomeSEXP s -> m (Either (MatcherError s) a) -- | Returns current SomeSEXP. Never fails. somesexp :: Matcher s (SomeSEXP s) -- | Returns current SEXP if it is of the requested type, fails -- otherwise, returns TypeMissmatch in that case. sexp :: SSEXPTYPE ty -> Matcher s (SEXP s ty) -- | Run a submatcher on another SomeSEXP. All exceptions in the -- internal matcher are propagated to the parent one. This combinator -- allows to inspect nested structures without exiting the matcher, so -- it's possible to effectively combine it with alternative function. with :: SomeSEXP s -> Matcher s a -> Matcher s a -- | hexp lifted to Matcher, applies hexp to the current value and -- allows you to run internal matcher on it. Is useful when you need to -- inspect data using high level functions from Language.R. hexp :: SSEXPTYPE ty -> (HExp s ty -> Matcher s a) -> Matcher s a -- | Succeeds if current SomeSEXP is Null. null :: Matcher s () -- | Succeeds if current SomeSEXP is S4 object. This check is more -- accurate then using guardType S4 as it uses internal R's -- function to check if the object is S4. s4 :: Matcher s () -- | Succeeds if SomeSEXP is an S3 object of the given type. In -- general case it's better to use getS3Class because it will run -- same check, but also will return the class(es) of the current -- expression. -- -- This test is not expressible in terms of the guardType, because -- guardType does not see additional information about S3 types. And any -- raw object can be a class instance. s3 :: [String] -> Matcher s () -- | Continue execution if SEXP have required type. This check tests basic -- types of the expression like if it's integer, or real or character -- vector and such. If you need to test object type use s3 or -- s4 directly. guardType :: SEXPTYPE -> Matcher s () -- | Returns type of the current SEXP. Can never fail. typeOf :: Matcher s SEXPTYPE -- | Return the class of the S3 object, fails otherwise. getS3Class :: Matcher s [String] -- | Returns any attribute by its name if it exists. Fails with -- NoSuchAttribute otherwise. someAttribute :: String -> Matcher s (SomeSEXP s) -- | Typed version of the someAttribute call. In addition to -- retrieving value it's dynamically type checked. attribute :: SSEXPTYPE a -> String -> Matcher s (SEXP s a) -- | Match all attributes, takes a matcher and applies it to the each -- attribute exists, returns list of the attribute name, together with -- matcher result. If matcher returns Nothing - result is -- omitted.. attributes :: Matcher s (Maybe a) -> Matcher s [(String, a)] -- | Find an attribute in attribute list if it exists. lookupAttribute :: String -> Matcher s (Maybe (SomeSEXP s)) -- | Get names attribute. names :: Matcher s [String] -- | Get dim attribute. dim :: Matcher s [Int] -- | Get dimnames attribute. dimnames :: Matcher s [[String]] -- | Get rownames attribute. rownames :: Matcher s [String] -- | Match a factor. Returns the levels of the factor. factor :: Matcher s [String] -- | Convert String SEXP to the list of HExps. charList :: SEXP s 'String -> [String] -- | Execute first matcher that will not fail. choice :: [Matcher s a] -> Matcher s a -- | Matches a List object. list :: Int -> Matcher s a -> Matcher s [a] instance GHC.Generics.Generic (Language.R.Matcher.MatcherError s) instance GHC.Show.Show (Language.R.Matcher.MatcherError s) instance GHC.Base.Monad (Language.R.Matcher.Matcher s) instance Control.Monad.Fail.MonadFail (Language.R.Matcher.Matcher s) instance GHC.Base.Applicative (Language.R.Matcher.Matcher s) instance GHC.Base.Functor (Language.R.Matcher.Matcher s) instance GHC.Base.Alternative (Language.R.Matcher.Matcher s) instance GHC.Base.Semigroup (Language.R.Matcher.MatcherError s) instance GHC.Base.Monoid (Language.R.Matcher.MatcherError s) instance Control.DeepSeq.NFData (Language.R.Matcher.MatcherError s) -- | This class is not meant to be imported in any other circumstance than -- in a GHCi session. module H.Prelude.Interactive -- | The singleton kind-indexed type family. type family Sing :: k -> Type data RError RError :: String -> RError -- | R uses three-valued logic. data {-# CTYPE "Logical" #-} Logical FALSE :: Logical TRUE :: Logical NA :: Logical -- | Constraint synonym grouping all expression forms into one class. -- According to R internals, an expression is usually a Lang, but -- can sometimes also be an Expr or a Symbol. type IsExpression (a :: SEXPTYPE) = (SingI a, a :∈ [Lang, Expr, Symbol]) -- | IsPairList a holds iff R's is.pairlist() returns -- TRUE. type IsPairList (a :: SEXPTYPE) = (SingI a, a :∈ [List, Nil]) -- | IsList a holds iff R's is.list() returns -- TRUE. type IsList (a :: SEXPTYPE) = (SingI a, a :∈ 'Char : 'Logical : 'Int : 'Real : 'Complex : 'String : 'Vector : 'Expr : 'WeakRef : 'Raw : List : '[]) -- | Non-atomic vector forms. See src/main/memory.c:SET_VECTOR_ELT -- in the R source distribution. type IsGenericVector (a :: SEXPTYPE) = (SingI a, a :∈ [Vector, Expr, WeakRef]) -- | Constraint synonym grouping all vector forms into one class. -- IsVector a holds iff R's is.vector() returns -- TRUE. type IsVector (a :: SEXPTYPE) = (SingI a, a :∈ 'Char : 'Logical : 'Int : 'Real : 'Complex : 'String : 'Vector : 'Expr : 'WeakRef : 'Raw : '[]) -- | Used where the R documentation speaks of "pairlists", which are really -- just regular lists. type PairList = List data SSEXPTYPE :: SEXPTYPE -> Type [SNil] :: SSEXPTYPE ('Nil :: SEXPTYPE) [SSymbol] :: SSEXPTYPE ('Symbol :: SEXPTYPE) [SList] :: SSEXPTYPE ('List :: SEXPTYPE) [SClosure] :: SSEXPTYPE ('Closure :: SEXPTYPE) [SEnv] :: SSEXPTYPE ('Env :: SEXPTYPE) [SPromise] :: SSEXPTYPE ('Promise :: SEXPTYPE) [SLang] :: SSEXPTYPE ('Lang :: SEXPTYPE) [SSpecial] :: SSEXPTYPE ('Special :: SEXPTYPE) [SBuiltin] :: SSEXPTYPE ('Builtin :: SEXPTYPE) [SChar] :: SSEXPTYPE ('Char :: SEXPTYPE) [SLogical] :: SSEXPTYPE ('Logical :: SEXPTYPE) [SInt] :: SSEXPTYPE ('Int :: SEXPTYPE) [SReal] :: SSEXPTYPE ('Real :: SEXPTYPE) [SComplex] :: SSEXPTYPE ('Complex :: SEXPTYPE) [SString] :: SSEXPTYPE ('String :: SEXPTYPE) [SDotDotDot] :: SSEXPTYPE ('DotDotDot :: SEXPTYPE) [SAny] :: SSEXPTYPE ('Any :: SEXPTYPE) [SVector] :: SSEXPTYPE ('Vector :: SEXPTYPE) [SExpr] :: SSEXPTYPE ('Expr :: SEXPTYPE) [SBytecode] :: SSEXPTYPE ('Bytecode :: SEXPTYPE) [SExtPtr] :: SSEXPTYPE ('ExtPtr :: SEXPTYPE) [SWeakRef] :: SSEXPTYPE ('WeakRef :: SEXPTYPE) [SRaw] :: SSEXPTYPE ('Raw :: SEXPTYPE) [SS4] :: SSEXPTYPE ('S4 :: SEXPTYPE) [SNew] :: SSEXPTYPE ('New :: SEXPTYPE) [SFree] :: SSEXPTYPE ('Free :: SEXPTYPE) [SFun] :: SSEXPTYPE ('Fun :: SEXPTYPE) -- | A SEXP of unknown form. data SomeSEXP s SomeSEXP :: {-# UNPACK #-} !SEXP s a -> SomeSEXP s -- | The basic type of all R expressions, classified by the form of the -- expression, and the memory region in which it has been allocated. data SEXP s (a :: SEXPTYPE) -- | Deconstruct a SomeSEXP. Takes a continuation since otherwise -- the existentially quantified variable hidden inside SomeSEXP -- would escape. unSomeSEXP :: SomeSEXP s -> (forall a. SEXP s a -> r) -> r -- | Return the "type" tag (aka the form tag) of the given SEXP. -- This function is pure because the type of an object does not normally -- change over the lifetime of the object. typeOf :: SEXP s a -> SEXPTYPE -- | Cast the type of a SEXP into another type. This function is -- partial: at runtime, an error is raised if the source form tag does -- not match the target form tag. cast :: SSEXPTYPE a -> SomeSEXP s -> SEXP s a -- | Cast form of first argument to that of the second argument. asTypeOf :: SomeSEXP s -> SEXP s a -> SEXP s a -- | Unsafe coercion from one form to another. This is unsafe, in the sense -- that using this function improperly could cause code to crash in -- unpredictable ways. Contrary to cast, it has no runtime cost -- since it does not introduce any dynamic check at runtime. unsafeCoerce :: SEXP s a -> SEXP s b type Region m = PrimState m -- | The class of R interaction monads. For safety, in compiled code we -- normally use the R monad. For convenience, in a GHCi session, -- we normally use the IO monad directly (by means of a -- MonadR instance for IO, imported only in GHCi). class (Applicative m, MonadIO m, MonadCatch m, MonadMask m, PrimMonad m) => MonadR m where { -- | A reification of an R execution context, i.e. a "session". data ExecContext m :: *; } -- | Lift an IO action. io :: MonadR m => IO a -> m a -- | Acquire ownership in the current region of the given object. This -- means that the liveness of the object is guaranteed so long as the -- current region remains active (the R garbage collector will not -- attempt to free it). acquire :: (MonadR m, s ~ V) => SEXP s a -> m (SEXP (Region m) a) -- | Acquire ownership in the current region of the given object. This -- means that the liveness of the object is guaranteed so long as the -- current region remains active (the R garbage collector will not -- attempt to free it). acquire :: (MonadR m, MonadIO m, Region m ~ G) => SEXP s a -> m (SEXP (Region m) a) -- | Get the current execution context. getExecContext :: MonadR m => m (ExecContext m) -- | Provides no static guarantees that resources do not extrude the scope -- of their region. Acquired resources are not freed automatically upon -- exit. For internal use only. unsafeRunWithExecContext :: MonadR m => m a -> ExecContext m -> IO a -- | acquire for SomeSEXP. acquireSome :: MonadR m => SomeSEXP V -> m (SomeSEXP (Region m)) -- | Declare memory management for this value to be automatic. That is, the -- memory associated with it may be freed as soon as the garbage -- collector notices that it is safe to do so. -- -- Values with automatic memory management are tagged with the global -- region. The reason is that just like for other global values, -- deallocation of the value can never be observed. Indeed, it is a mere -- "optimization" to deallocate the value sooner - it would still be -- semantically correct to never deallocate it at all. automatic :: MonadR m => SEXP s a -> m (SEXP G a) -- | automatic for SomeSEXP. automaticSome :: MonadR m => SomeSEXP s -> m (SomeSEXP G) pokeRVariables :: RVariables -> IO () isRInteractive :: Ptr CInt signalHandlersPtr :: Ptr CInt -- | Special value to which all symbols unbound in the current environment -- resolve to. unboundValue :: SEXP G 'Symbol -- | R's NULL value. nilValue :: SEXP G 'Nil -- | Value substituted for all missing actual arguments of a function call. missingArg :: SEXP G 'Symbol -- | The base environment. baseEnv :: SEXP G 'Env -- | The empty environment. emptyEnv :: SEXP G 'Env -- | The global environment. globalEnv :: SEXP G 'Env inputHandlers :: Ptr InputHandler -- | Manually trigger processing all pending events. Useful when at an -- interactive prompt and no event loop is running. refresh :: MonadR m => m () -- | A view of R's internal SEXP structure as an algebraic datatype. -- Because this is in fact a GADT, the use of named record fields is not -- possible here. Named record fields give rise to functions for whom it -- is not possible to assign a reasonable type (existentially quantified -- type variables would escape). -- -- See -- https://cran.r-project.org/doc/manuals/r-release/R-ints.html#SEXPTYPEs. data HExp :: * -> SEXPTYPE -> * -- | The NULL value (NILSXP). [Nil] :: HExp s 'Nil -- | A symbol (SYMSXP). [Symbol] :: a :∈ ['Char, 'Nil] => SEXP s a -> SEXP s b -> SEXP s c -> HExp s 'Symbol -- | A list (LISTSXP). [List] :: (IsPairList b, c :∈ ['Symbol, 'Nil]) => SEXP s a -> SEXP s b -> SEXP s c -> HExp s 'List -- | An environment (ENVSXP). [Env] :: (IsPairList a, b :∈ ['Env, 'Nil], c :∈ ['Vector, 'Nil]) => SEXP s a -> SEXP s b -> SEXP s c -> HExp s 'Env -- | A closure (CLOSXP). [Closure] :: IsPairList a => SEXP s a -> SEXP s b -> SEXP s 'Env -> HExp s 'Closure -- | A promise (PROMSXP). [Promise] :: (IsExpression b, c :∈ ['Env, 'Nil]) => SEXP s a -> SEXP s b -> SEXP s c -> HExp s 'Promise -- | Language objects (LANGSXP) are calls (including formulae and -- so on). Internally they are pairlists with first element a reference -- to the function to be called with remaining elements the actual -- arguments for the call (and with the tags if present giving the -- specified argument names). Although this is not enforced, many places -- in the R code assume that the pairlist is of length one or more, often -- without checking. [Lang] :: (IsExpression a, IsPairList b) => SEXP s a -> SEXP s b -> HExp s 'Lang -- | A special (built-in) function call (SPECIALSXP). It carries -- an offset into the table of primitives but for our purposes is opaque. [Special] :: HExp s 'Special -- | A BUILTINSXP. This is similar to Special, except the -- arguments to a Builtin are always evaluated. [Builtin] :: HExp s 'Builtin -- | An internal character string (CHARSXP). [Char] :: {-# UNPACK #-} !Vector 'Char Word8 -> HExp s 'Char -- | A logical vector (LGLSXP). [Logical] :: {-# UNPACK #-} !Vector 'Logical Logical -> HExp s 'Logical -- | An integer vector (INTSXP). [Int] :: {-# UNPACK #-} !Vector 'Int Int32 -> HExp s 'Int -- | A numeric vector (REALSXP). [Real] :: {-# UNPACK #-} !Vector 'Real Double -> HExp s 'Real -- | A complex vector (CPLXSXP). [Complex] :: {-# UNPACK #-} !Vector 'Complex (Complex Double) -> HExp s 'Complex -- | A character vector (STRSXP). [String] :: {-# UNPACK #-} !Vector 'String (SEXP V 'Char) -> HExp s 'String -- | A special type of LISTSXP for the value bound to a -- ... symbol [DotDotDot] :: IsPairList a => SEXP s a -> HExp s 'List -- | A list/generic vector (VECSXP). [Vector] :: {-# UNPACK #-} !Int32 -> {-# UNPACK #-} !Vector 'Vector (SomeSEXP V) -> HExp s 'Vector -- | An expression vector (EXPRSXP). [Expr] :: {-# UNPACK #-} !Int32 -> {-# UNPACK #-} !Vector 'Expr (SomeSEXP V) -> HExp s 'Expr -- | A ‘byte-code’ object generated by R (BCODESXP). [Bytecode] :: HExp s 'Bytecode -- | An external pointer (EXTPTRSXP) [ExtPtr] :: c :∈ ['Symbol, 'Nil] => Ptr () -> SEXP s b -> SEXP s c -> HExp s 'ExtPtr -- | A weak reference (WEAKREFSXP). [WeakRef] :: (a :∈ ['Env, 'ExtPtr, 'Nil], c :∈ ['Closure, 'Builtin, 'Special, 'Nil], d :∈ ['WeakRef, 'Nil]) => SEXP s a -> SEXP s b -> SEXP s c -> SEXP s d -> HExp s 'WeakRef -- | A raw vector (RAWSXP). [Raw] :: {-# UNPACK #-} !Vector 'Raw Word8 -> HExp s 'Raw -- | An S4 class which does not consist solely of a simple type such as an -- atomic vector or function (S4SXP). [S4] :: a :∈ ['Symbol, 'Nil] => SEXP s a -> HExp s 'S4 -- | Heterogeneous equality. (===) :: TestEquality f => f a -> f b -> Bool -- | A view function projecting a view of SEXP as an algebraic -- datatype, that can be analyzed through pattern matching. hexp :: SEXP s a -> HExp s a -- | Project the vector out of SEXPs. vector :: IsVector a => SEXP s a -> Vector a (ElemRep V a) -- | Configuration options for the R runtime. Configurations form monoids, -- so arguments can be accumulated left-to-right through monoidal -- composition. data Config Config :: Last String -> [String] -> Last Bool -> Config -- | Program name. If Nothing then the value of getProgName -- will be used. [configProgName] :: Config -> Last String -- | Command-line arguments. [configArgs] :: Config -> [String] -- | Set to True if you're happy to let R install its own signal -- handlers during initialization. By default R sets following signal -- handlers: -- -- [configSignalHandlers] :: Config -> Last Bool -- | 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. data R s a -- | 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). -- -- throws Error. Generaly any R function may throw -- RError that is safe to be cached and computation can proceed. -- However RError will cancel entire R block. So in order to -- catch exception in more fine grained way one has to use function -- tryCatch inside R block. runRegion :: NFData a => (forall s. R s a) -> IO a unsafeRunRegion :: NFData a => R s a -> IO a -- | Default argument to pass to initialize. defaultConfig :: Config -- | 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. initialize :: Config -> IO () -- | Finalize an R instance. finalize :: IO () -- | Values that can be converted to SEXP. class SingI ty => Literal a ty | a -> ty -- | Internal function for converting a literal to a SEXP value. You -- probably want to be using mkSEXP instead. mkSEXPIO :: Literal a ty => a -> IO (SEXP V ty) fromSEXP :: Literal a ty => SEXP s ty -> a -- | Internal function for converting a literal to a SEXP value. You -- probably want to be using mkSEXP instead. mkSEXPIO :: (Literal a ty, IsVector ty, Literal [a] ty) => a -> IO (SEXP V ty) fromSEXP :: (Literal a ty, IsVector ty, Literal [a] ty) => SEXP s ty -> a -- | Create a SEXP value and protect it in current region mkSEXP :: (Literal a b, MonadR m) => a -> m (SEXP (Region m) b) -- | Like fromSEXP, but with no static type satefy. Performs a -- dynamic (i.e. at runtime) check instead. fromSomeSEXP :: forall s a form. Literal a form => SomeSEXP s -> a -- | Like fromSomeSEXP, but behaves like the as.* family of -- functions in R, by performing a best effort conversion to the target -- form (e.g. rounds reals to integers, etc) for atomic types. dynSEXP :: forall a s ty. Literal a ty => SomeSEXP s -> a mkSEXPVector :: (Storable (ElemRep s a), IsVector a) => SSEXPTYPE a -> [IO (ElemRep s a)] -> SEXP s a mkSEXPVectorIO :: (Storable (ElemRep s a), IsVector a) => SSEXPTYPE a -> [IO (ElemRep s a)] -> IO (SEXP s a) mkProtectedSEXPVector :: IsVector b => SSEXPTYPE b -> [SEXP s a] -> SEXP s b mkProtectedSEXPVectorIO :: IsVector b => SSEXPTYPE b -> [SEXP s a] -> IO (SEXP s b) -- | Create a pairlist from an association list. Result is either a -- pairlist or nilValue if the input is the null list. These are -- two distinct forms. Hence why the type of this function is not more -- precise. toPairList :: MonadR m => [(String, SomeSEXP (Region m))] -> m (SomeSEXP (Region m)) -- | Create an association list from a pairlist. R Pairlists are -- nil-terminated chains of nested cons cells, as in LISP. fromPairList :: SomeSEXP s -> [(String, SomeSEXP s)] funToSEXP :: HFunWrap a b => (b -> IO (FunPtr b)) -> a -> IO (SEXP s 'ExtPtr) -- | Parse file and perform some actions on parsed file. -- -- This function uses continuation because this is an easy way to make -- operations GC-safe. -- | Deprecated: Use [r| parse(file="pathtofile") |] instead. parseFile :: FilePath -> (SEXP s 'Expr -> IO a) -> IO a -- | Deprecated: Use [r| parse(text=...) |] instead. parseText :: String -> Bool -> IO (SEXP V 'Expr) -- | Internalize a symbol name. install :: MonadR m => String -> m (SEXP V 'Symbol) -- | Create an R character string from a Haskell string. -- | Deprecated: Use mkSEXP instead string :: String -> IO (SEXP V 'Char) -- | Create an R string vector from a Haskell string. -- | Deprecated: Use mkSEXP instead strings :: String -> IO (SEXP V 'String) -- | Evaluate a (sequence of) expression(s) in the given environment, -- returning the value of the last. evalEnv :: MonadR m => SEXP s a -> SEXP s 'Env -> m (SomeSEXP (Region m)) -- | Evaluate a (sequence of) expression(s) in the global environment. eval :: MonadR m => SEXP s a -> m (SomeSEXP (Region m)) -- | Silent version of eval function that discards it's result. eval_ :: MonadR m => SEXP s a -> m () -- | Throw an R error as an exception. throwR :: MonadR m => SEXP s 'Env -> m a -- | Cancel any ongoing R computation in the current process. After -- interruption an RError exception will be raised. -- -- This call is safe to run in any thread. If there is no R computation -- running, the next computaion will be immediately cancelled. Note that -- R will only interrupt computations at so-called "safe points" (in -- particular, not in the middle of a C call). cancel :: IO () -- | Throw an R exception with specified message. throwRMessage :: MonadR m => String -> m a -- | An R value, expressed as an R expression, in R's syntax. r :: QuasiQuoter -- | Quasiquoter for pure R code (no side effects) and that does not depend -- on the global environment (referential transparency). This means that -- all symbols must appear qualified with a package namespace (whose -- bindings are locked by default), the code must not affect R shared -- state in any way, including the global environment, and must not -- perform I/O. rsafe :: QuasiQuoter -- | Map backwards slashes to forward slashes. -- -- Find all occurences of antiquotations. -- -- This function works by parsing the user's R code in a separate R -- process. As a nice side-effect, it will detect and return any syntax -- errors in the quasi-quoted R code. -- -- This function is exposed only for testing; you probably don't need to -- call it in the user code. collectAntis :: String -> IO (Either String [String]) class PrintR a printR :: (PrintR a, MonadR m) => a -> m () -- | A form of the printR function that is more convenient in an -- interactive session. p :: (MonadR m, PrintR a) => m a -> m () -- | A form of the printR function that is more convenient in an -- interactive session. -- | Deprecated: Use p instead. printQuote :: (MonadR m, PrintR a) => m a -> m () instance H.Prelude.Interactive.PrintR (Foreign.R.Internal.SEXP s a) instance H.Prelude.Interactive.PrintR (Foreign.R.Internal.SomeSEXP s) instance Control.Monad.R.Class.MonadR GHC.Types.IO