Safe Haskell | None |
---|---|
Language | Haskell2010 |
Dovetail
Synopsis
- module Dovetail.Types
- module Dovetail.FFI
- module Dovetail.FFI
- module Dovetail.FFI.Builder
- data InterpretT m a
- runInterpretT :: Monad m => InterpretT m a -> m (Either (InterpretError m) a)
- runInterpret :: Interpret a -> Either (InterpretError Identity) a
- liftEvalT :: Monad m => EvalT m a -> InterpretT m a
- runInterpretTWithDebugger :: (MonadIO m, MonadFix m, MonadMask m) => InterpretT m a -> m ()
- data InterpretError m
- renderInterpretError :: RenderValueOptions -> InterpretError m -> String
- ffi :: Monad m => FFI m -> InterpretT m ()
- build :: MonadFix m => Text -> InterpretT m (Module Ann)
- buildCoreFn :: MonadFix m => ExternsFile -> Module Ann -> InterpretT m (Module Ann)
- data BuildError
- = UnableToParse (NonEmpty ParserError)
- | UnableToCompile MultipleErrors
- | InternalError
- renderBuildError :: BuildError -> String
- eval :: (MonadFix m, ToValueRHS m a) => Maybe ModuleName -> Text -> InterpretT m (a, SourceType)
- evalCoreFn :: (MonadFix m, ToValueRHS m a) => Expr Ann -> InterpretT m a
- evalMain :: (MonadFix m, ToValueRHS m a) => ModuleName -> InterpretT m a
- type Eval = EvalT Identity
- newtype EvalT m a = EvalT {
- unEvalT :: ReaderT (EvaluationContext m) (ExceptT (EvaluationError m) m) a
- type Env m = Map (Qualified Ident) (Value m)
- runEvalT :: EvalT m a -> m (Either (EvaluationError m) a)
- runEval :: Eval a -> Either (EvaluationError Identity) a
- class ToValueRHS m a where
- toValueRHS :: a -> EvalT m (Value m)
- fromValueRHS :: EvalT m (Value m) -> a
- class MonadFix m => ToValue m a where
- repl :: (MonadFix m, MonadIO m, MonadMask m) => Maybe ModuleName -> InterpretT m ()
- type Ann = (SourceSpan, [Comment], Maybe SourceType, Maybe Meta)
- data Expr a
- data Module a
Documentation
module Dovetail.Types
module Dovetail.FFI
module Dovetail.FFI
module Dovetail.FFI.Builder
High-level API
data InterpretT m a Source #
A monad transformer for high-level tasks involving PureScript code, including separate compilation. Its job is to keep track of available modules, any foreign imports from Haskell code, and run PureScript code.
Note: do not confuse this monad transformer with EvalT
, which is only
responsible for powering evaluation of PureScript expressions.
The transformed monad is used to track any benign side effects that might be
exposed via the foreign function interface to PureScript code, in the same sense
as EvalT
.
Instances
runInterpretT :: Monad m => InterpretT m a -> m (Either (InterpretError m) a) Source #
Run a computation in the InterpretT
monad, possibly returning an error.
Note: errors can occur during module building or evaluation (i.e. module loading).
The runInterpret
function is a simpler alternative in the case where benign
side-effects are not needed.
For example:
runInterpretModule do -- Load the prelude
(Eval Text) doffi
prelude
-- Build a module from sourcebuild
"module Main where main = \"example\"" -- runInterpretffi
prelude
_ <-build
"module Main where main = \"example\"" -- Evaluate the main functionevalMain
(ModuleName
"Main")
runInterpret :: Interpret a -> Either (InterpretError Identity) a Source #
liftEvalT :: Monad m => EvalT m a -> InterpretT m a Source #
A convenience function for running EvalT
computations in InterpretT
,
reporting errors via InterpretError
.
Debugging
runInterpretTWithDebugger :: (MonadIO m, MonadFix m, MonadMask m) => InterpretT m a -> m () Source #
Like runInterpretT
, but starts an interactive debugging session in the
event of a debugging error.
Error messages
data InterpretError m Source #
The type of errors that can occur in the InterpretT
monad.
Constructors
ErrorDuringEvaluation (EvaluationError m) | Evaluation errors can occur during the initial evaluation of the module when it is loaded into the environment. |
ErrorDuringBuild BuildError | Build errors can occur if we are building modules from source or corefn. |
Instances
Monad m => MonadError (InterpretError m) (InterpretT m) Source # | |
Defined in Dovetail Methods throwError :: InterpretError m -> InterpretT m a # catchError :: InterpretT m a -> (InterpretError m -> InterpretT m a) -> InterpretT m a # |
Foreign function interface
Building PureScript source
build :: MonadFix m => Text -> InterpretT m (Module Ann) Source #
Build a PureScript module from source, and make its exported functions available during subsequent evaluations.
buildCoreFn :: MonadFix m => ExternsFile -> Module Ann -> InterpretT m (Module Ann) Source #
Build a PureScript module from corefn, and make its exported functions available during subsequent evaluations.
The corefn module may be preprepared, for example by compiling from source text using the functions in the Dovetail.Build module.
data BuildError Source #
Constructors
UnableToParse (NonEmpty ParserError) | |
UnableToCompile MultipleErrors | |
InternalError |
Instances
Show BuildError Source # | |
Defined in Dovetail.Build Methods showsPrec :: Int -> BuildError -> ShowS # show :: BuildError -> String # showList :: [BuildError] -> ShowS # |
renderBuildError :: BuildError -> String Source #
Evaluating expressions
Arguments
:: (MonadFix m, ToValueRHS m a) | |
=> Maybe ModuleName | The name of the "default module" whose exports will be made available unqualified to the evaluated expression. |
-> Text | |
-> InterpretT m (a, SourceType) |
Evaluate a PureScript expression from source
evalCoreFn :: (MonadFix m, ToValueRHS m a) => Expr Ann -> InterpretT m a Source #
Evaluate a PureScript corefn expression and return the result.
Note: The expression is not type-checked by the PureScript typechecker.
See the documentation for ToValueRHS
for valid result types.
evalMain :: (MonadFix m, ToValueRHS m a) => ModuleName -> InterpretT m a Source #
Evaluate main
in the specified module and return the result.
type Eval = EvalT Identity Source #
Non-transformer version of EvalT
, useful in any settings where the FFI
does not use any side effects during evaluation.
The monad used by the interpreter, which supports error reporting for errors which can occur during evaluation.
The transformed monad is used to track any benign side effects that might be exposed via the foreign function interface to PureScript code.
Constructors
EvalT | |
Fields
|
Instances
MonadTrans EvalT Source # | |
Defined in Dovetail.Types | |
(ToValue m a, n ~ m) => ToValueRHS m (EvalT n a) Source # | |
Defined in Dovetail.Evaluate | |
Monad m => Monad (EvalT m) Source # | |
Functor m => Functor (EvalT m) Source # | |
MonadFix m => MonadFix (EvalT m) Source # | |
Defined in Dovetail.Types | |
Monad m => Applicative (EvalT m) Source # | |
Monad m => MonadError (EvaluationError m) (EvalT m) Source # | |
Defined in Dovetail.Types Methods throwError :: EvaluationError m -> EvalT m a # catchError :: EvalT m a -> (EvaluationError m -> EvalT m a) -> EvalT m a # | |
Monad m => MonadReader (EvaluationContext m) (EvalT m) Source # | |
Defined in Dovetail.Types Methods ask :: EvalT m (EvaluationContext m) # local :: (EvaluationContext m -> EvaluationContext m) -> EvalT m a -> EvalT m a # reader :: (EvaluationContext m -> a) -> EvalT m a # |
class ToValueRHS m a where Source #
ToValue
should support functions with types such as
a -> EvalT m b a -> b -> EvalT m c a -> b -> c -> EvalT m d (a -> EvalT m b) -> EvalT m c (a -> b -> EvalT m c) -> EvalT m d
Note that every type in a return position is wrapped in the EvalT
monad
transformer. This is because evaluation in general may result in errors.
However, a naive translation would result in too many applications of EvalT
.
Specifically, we do not want to require types such as these, in which EvalT
appears on the right hand side of every function arrow:
a -> EvalT m b (b -> EvalT m c) a -> EvalT m b (b -> EvalT m (c -> EvalT m d))
For this reason, the ToValue
instance for functions delegates to this
type class for the type on the right hand side of the function. It skips the
application of EvalT
for nested function types.
Instances
(ToValue m a, n ~ m) => ToValueRHS m (EvalT n a) Source # | |
Defined in Dovetail.Evaluate | |
(MonadFix m, ToValue m a, ToValueRHS m b) => ToValueRHS m (a -> b) Source # | |
Defined in Dovetail.Evaluate Methods toValueRHS :: (a -> b) -> EvalT m (Value m) Source # fromValueRHS :: EvalT m (Value m) -> a -> b Source # |
class MonadFix m => ToValue m a where Source #
Values which can be communicated across the FFI boundary from Haskell to PureScript.
Instances should identify and document any valid representations as a subset
of the semantic domain Value
. Such a subset can be identified by an
injective function toValue
, and a partial inverse, fromValue
, defined
on the image of toValue
.
Laws:
fromValue . toValue = pure
Minimal complete definition
Nothing
Methods
toValue :: a -> Value m Source #
The default implementation uses generic deriving to identify a Haskell record type with a single data constructor with a PureScript record with the same field names.
Instances
MonadFix m => ToValue m Bool Source # | Haskell booleans are represented by boolean values. |
MonadFix m => ToValue m Char Source # | The Haskell |
MonadFix m => ToValue m Text Source # | The Haskell |
MonadFix m => ToValue m Double Source # | The Haskell |
MonadFix m => ToValue m Integer Source # | The Haskell |
MonadFix m => ToValue m UnknownJSON Source # | |
Defined in Dovetail.JSON | |
ToValue m a => ToValue m (Vector a) Source # | Haskell vectors are represented as homogeneous vectors of values, each of which are valid representations of the element type. |
MonadFix m => ToValue m (Value m) Source # | |
ToValue m a => ToValue m (Nullable a) Source # | |
(MonadFix m, ToValue m a, ToValueRHS m b) => ToValue m (a -> b) Source # | Haskell functions are represented as closures which take valid representations for the domain type to valid representations of the codomain type. |
REPL
Arguments
:: (MonadFix m, MonadIO m, MonadMask m) | |
=> Maybe ModuleName | The default module, whose members will be available unqualified in scope |
-> InterpretT m () |
Start an interactive debugger (REPL) session.