The primary monad for code using Python.
9. Monads
The core monads of Nerodia are PyIO and its error-less variant PyBaseIO,
which equip BaseIO with a Python context. Each provides a utility function
to convert it back to its Python-less equivalent by allocating a temporary
Python context for the call. However, where possible, they should be run within
another Python-equipped monad to efficiently reuse its context.
Runs the PyIO function in IO.
If an exception is raised, it will be formatted in the standard Python manner
(see PyBaseException.sprint) and reported as an IO.userError.
This creates a new temporary Python context for the call.
As such, it should only be used when a Python context is not available.
For instance, this can be used in main to run a PyIO function.
It is also used to run PyIO in #eval.
Example
def main : IO Unit := do
let pyVer ← Nerodia.PyIO.toIO do
let sys ← Nerodia.import "sys"
let ver ← sys.getAttrByString "version"
return (← ver.str).toString
IO.println pyVer
Runs the PyIO function in EIO.
This creates a new temporary Python context for the call.
As such, it should only be used when another Python context is not available.
Otherwise, lift x into a supporting monad.
9.1. C Returns
Return contexts used for optimized C functions. They are not monads themselves,
but they automatically lift into their corresponding PyIO-style monad (i.e.,
CPyIO to PyIO, CPyBaseIO to PyBaseIO).
Return context for external CPython functions that return an object and may raise an exception.
Not a monad itself, but lifts into monads equipped with a Python context.
Return context for external CPython functions that return an object and cannot raise an exception.
Not a monad itself, but lifts into monads equipped with a Python context.
Return type for external CPython functions that may error but do not return a Python object.
Not a monad itself, but lifts into monads equipped with a Python context.