Methods
fromSession :: FromSession m amodifySessionRef :: ModifySessionRef m arunGhc :: RunGhc m a
Instances1MonadInterpreter
(MonadIO m, MonadMask m, Functor m) => MonadInterpreter (InterpreterT m)Defined in hint-0.9.0.8 · Hint.InterpreterT
:: a typeCtrl KGHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05
Modulehint-0.9.0.8Haskell2010
fromSession :: FromSession m amodifySessionRef :: ModifySessionRef m arunGhc :: RunGhc m a(MonadIO m, MonadMask m, Functor m) => MonadInterpreter (InterpreterT m)Defined in hint-0.9.0.8 · Hint.InterpreterTMonadTrans InterpreterTDefined in hint-0.9.0.8 · Hint.InterpreterTMonad m => Monad (InterpreterT m)Defined in hint-0.9.0.8 · Hint.InterpreterTFunctor m => Functor (InterpreterT m)Defined in hint-0.9.0.8 · Hint.InterpreterTMonad m => Applicative (InterpreterT m)Defined in hint-0.9.0.8 · Hint.InterpreterTMonadIO m => MonadIO (InterpreterT m)Defined in hint-0.9.0.8 · Hint.InterpreterT(MonadIO m, MonadMask m) => MonadCatch (InterpreterT m)Defined in hint-0.9.0.8 · Hint.InterpreterT(MonadIO m, MonadMask m) => MonadMask (InterpreterT m)Defined in hint-0.9.0.8 · Hint.InterpreterTMonadCatch m => MonadThrow (InterpreterT m)Defined in hint-0.9.0.8 · Hint.InterpreterT(MonadIO m, MonadMask m, Functor m) => MonadInterpreter (InterpreterT m)Defined in hint-0.9.0.8 · Hint.InterpreterTExecutes the interpreter. Returns Left InterpreterError in case of error.
NB. In hint-0.7.0 and earlier, the underlying ghc was accidentally overwriting certain signal handlers (SIGINT, SIGHUP, SIGTERM, SIGQUIT on Posix systems, Ctrl-C handler on Windows).
Available options are:
Retrieves the value of an option.
Use this function to set or modify the value of any option. It is invoked like this:
set [opt1 := val1, opt2 := val2,... optk := valk]Language extensions in use by the interpreter.
Default is: [] (i.e. none, pure Haskell 98)
List of the extensions known by the interpreter.
This represents language extensions beyond Haskell 98
that are supported by GHC (it was taken from
Cabal's Language.Haskell.Extension)
OverlappingInstancesUndecidableInstancesIncoherentInstancesDoRecRecursiveDoParallelListCompMultiParamTypeClassesMonomorphismRestrictionFunctionalDependenciesRank2TypesRankNTypesPolymorphicComponentsExistentialQuantificationScopedTypeVariablesPatternSignaturesImplicitParamsFlexibleContextsFlexibleInstancesEmptyDataDeclsCPPKindSignaturesBangPatternsTypeSynonymInstancesTemplateHaskellForeignFunctionInterfaceArrowsGenericsImplicitPreludeNamedFieldPunsPatternGuardsGeneralizedNewtypeDerivingExtensibleRecordsRestrictedTypeSynonymsHereDocumentsMagicHashTypeFamiliesStandaloneDerivingUnicodeSyntaxUnliftedFFITypesInterruptibleFFICApiFFILiberalTypeSynonymsTypeOperatorsRecordWildCardsRecordPunsDisambiguateRecordFieldsTraditionalRecordSyntaxOverloadedStringsGADTsGADTSyntaxMonoPatBindsRelaxedPolyRecExtendedDefaultRulesUnboxedTuplesDeriveDataTypeableDeriveGenericDefaultSignaturesInstanceSigsConstrainedClassMethodsPackageImportsImpredicativeTypesNewQualifiedOperatorsPostfixOperatorsQuasiQuotesTransformListCompMonadComprehensionsViewPatternsXmlSyntaxRegularPatternsTupleSectionsGHCForeignImportPrimNPlusKPatternsDoAndIfThenElseMultiWayIfLambdaCaseRebindableSyntaxExplicitForAllDatatypeContextsMonoLocalBindsDeriveFunctorDeriveTraversableDeriveFoldableNondecreasingIndentationSafeImportsSafeTrustworthyUnsafeConstraintKindsPolyKindsDataKindsParallelArraysRoleAnnotationsOverloadedListsEmptyCaseAutoDeriveTypeableNegativeLiteralsBinaryLiteralsNumDecimalsNullaryTypeClassesExplicitNamespacesAllowAmbiguousTypesJavaScriptFFIPatternSynonymsPartialTypeSignaturesNamedWildCardsDeriveAnyClassDeriveLiftStaticPointersStrictDataStrictApplicativeDoDuplicateRecordFieldsTypeApplicationsTypeInTypeUndecidableSuperClassesMonadFailDesugaringTemplateHaskellQuotesOverloadedLabelsTypeFamilyDependenciesNoOverlappingInstancesNoUndecidableInstancesNoIncoherentInstancesNoDoRecNoRecursiveDoNoParallelListCompNoMultiParamTypeClassesNoMonomorphismRestrictionNoFunctionalDependenciesNoRank2TypesNoRankNTypesNoPolymorphicComponentsNoExistentialQuantificationNoScopedTypeVariablesNoPatternSignaturesNoImplicitParamsNoFlexibleContextsNoFlexibleInstancesNoEmptyDataDeclsNoCPPNoKindSignaturesNoBangPatternsNoTypeSynonymInstancesNoTemplateHaskellNoForeignFunctionInterfaceNoArrowsNoGenericsNoImplicitPreludeNoNamedFieldPunsNoPatternGuardsNoGeneralizedNewtypeDerivingNoExtensibleRecordsNoRestrictedTypeSynonymsNoHereDocumentsNoMagicHashNoTypeFamiliesNoStandaloneDerivingNoUnicodeSyntaxNoUnliftedFFITypesNoInterruptibleFFINoCApiFFINoLiberalTypeSynonymsNoTypeOperatorsNoRecordWildCardsNoRecordPunsNoDisambiguateRecordFieldsNoTraditionalRecordSyntaxNoOverloadedStringsNoGADTsNoGADTSyntaxNoMonoPatBindsNoRelaxedPolyRecNoExtendedDefaultRulesNoUnboxedTuplesNoDeriveDataTypeableNoDeriveGenericNoDefaultSignaturesNoInstanceSigsNoConstrainedClassMethodsNoPackageImportsNoImpredicativeTypesNoNewQualifiedOperatorsNoPostfixOperatorsNoQuasiQuotesNoTransformListCompNoMonadComprehensionsNoViewPatternsNoXmlSyntaxNoRegularPatternsNoTupleSectionsNoGHCForeignImportPrimNoNPlusKPatternsNoDoAndIfThenElseNoMultiWayIfNoLambdaCaseNoRebindableSyntaxNoExplicitForAllNoDatatypeContextsNoMonoLocalBindsNoDeriveFunctorNoDeriveTraversableNoDeriveFoldableNoNondecreasingIndentationNoSafeImportsNoSafeNoTrustworthyNoUnsafeNoConstraintKindsNoPolyKindsNoDataKindsNoParallelArraysNoRoleAnnotationsNoOverloadedListsNoEmptyCaseNoAutoDeriveTypeableNoNegativeLiteralsNoBinaryLiteralsNoNumDecimalsNoNullaryTypeClassesNoExplicitNamespacesNoAllowAmbiguousTypesNoJavaScriptFFINoPatternSynonymsNoPartialTypeSignaturesNoNamedWildCardsNoDeriveAnyClassNoDeriveLiftNoStaticPointersNoStrictDataNoStrictNoApplicativeDoNoDuplicateRecordFieldsNoTypeApplicationsNoTypeInTypeNoUndecidableSuperClassesNoMonadFailDesugaringNoTemplateHaskellQuotesNoOverloadedLabelsNoTypeFamilyDependenciesUnknownExtension StringWhen set to True, every module in every available package is implicitly
imported qualified. This is very convenient for interactive
evaluation, but can be a problem in sandboxed environments
(e.g. System.Unsafe.unsafePerformIO is in scope).
Default value is True.
Observe that due to limitations in the GHC-API, when set to False, the
private symbols in interpreted modules will not be in scope.
The search path for source files. Observe that every time it is set,
it overrides the previous search path. The default is ["."].
Keep in mind that by a limitation in ghc, "." is always in scope.
Module names are _not_ filepaths.
Returns True if the module was interpreted.
Represent module import statement.
See setImportsF
Show ModuleImportDefined in hint-0.9.0.8 · Hint.BaseEq ModuleQualificationDefined in hint-0.9.0.8 · Hint.BaseShow ModuleQualificationDefined in hint-0.9.0.8 · Hint.BaseEq ImportListDefined in hint-0.9.0.8 · Hint.BaseShow ImportListDefined in hint-0.9.0.8 · Hint.BaseTries to load all the requested modules from their source file. Modules my be indicated by their ModuleName (e.g. "My.Module") or by the full path to its source file. Note that in order to use code from that module, you also need to call setImports (to use the exported types and definitions) or setTopLevelModules (to also use the private types and definitions).
The interpreter is reset both before loading the modules and in the event of an error.
IMPORTANT: Like in a ghci session, this will also load (and interpret) any dependency that is not available via an installed package. Make sure that you are not loading any module that is also being used to compile your application. In particular, you need to avoid modules that define types that will later occur in an expression that you will want to interpret.
The problem in doing this is that those types will have two incompatible representations at runtime: 1) the one in the compiled code and 2) the one in the interpreted code. When interpreting such an expression (bringing it to program-code) you will likely get a segmentation fault, since the latter representation will be used where the program assumes the former.
The rule of thumb is: never make the interpreter run on the directory with the source code of your program! If you want your interpreted code to use some type that is defined in your program, then put the defining module on a library and make your program depend on that package.
Returns the list of modules loaded with loadModules.
Sets the modules whose context is used during evaluation. All bindings of these modules are in scope, not only those exported.
Modules must be interpreted to use this function.
Sets the modules whose exports must be in context. These can be modules
previously loaded with loadModules, or modules from packages which hint is
aware of. This includes package databases specified to
unsafeRunInterpreterWithArgs by the -package-db=... parameter, and
packages specified by a ghc environment file created by cabal build --write-ghc-environment-files=always.
Warning: setImports, setImportsQ, and setImportsF are mutually exclusive. If you have a list of modules to be used qualified and another list unqualified, then you need to do something like
setImportsQ ((zip unqualified $ repeat Nothing) ++ qualifieds)A variant of setImports where modules them may be qualified. e.g.:
setImportsQ [(Prelude, Nothing), (Data.Map, Just .M)]
Here, "map" will refer to Prelude.map and "M.map" to Data.Map.map.
A variant of setImportsQ where modules may have an explicit import list. e.g.:
setImportsF [ModuleImport Prelude NotQualified NoImportList, ModuleImport Data.Text (QualifiedAs $ Just Text) (HidingList ["pack"])]All imported modules are cleared from the context, and
loaded modules are unloaded. It is similar to a :load in
GHCi, but observe that not even the Prelude will be in
context after a reset.
Eq ModuleElemDefined in hint-0.9.0.8 · Hint.ReflectionRead ModuleElemDefined in hint-0.9.0.8 · Hint.ReflectionShow ModuleElemDefined in hint-0.9.0.8 · Hint.ReflectionAn Id for a class, a type constructor, a data constructor, a binding, etc
Gets an abstract representation of all the entities exported by the module.
It is similar to the :browse command in GHCi.
Similar to typeChecks, but gives more information, e.g. the type errors.
Returns a string representation of the type of the expression.
Tests if the expression type checks.
NB. Be careful if unsafeSetGhcOption "-fdefer-type-errors" is used.
Perhaps unsurprisingly, that can falsely make typeChecks and typeChecksWithDetails
return True and Right _ respectively.
Returns a string representation of the kind of the type expression.
Returns a string representation of the normalized type expression.
This is what the :kind! GHCi command prints after =.
Evaluates an expression, given a witness for its monomorphic type.
Convenience functions to be used with interpret to provide witnesses.
Example:
interpret "head [True,False]" (as :: Bool)interpret "head $ map show [True,False]" infer >>= flip interpret (as :: Bool)Convenience functions to be used with interpret to provide witnesses.
Example:
interpret "head [True,False]" (as :: Bool)interpret "head $ map show [True,False]" infer >>= flip interpret (as :: Bool)eval expr will evaluate show expr.
It will succeed only if expr has type t and there is a Show
instance for t.
Evaluate a statement in the IO monad, possibly binding new names.
Example:
runStmt "x <- return 42"
runStmt "print x"UnknownError StringWontCompile [GhcError]NotAllowed StringGhcException StringGhcExceptions from the underlying GHC API are caught and rethrown as this.
Show InterpreterErrorDefined in hint-0.9.0.8 · Hint.BaseException InterpreterErrorDefined in hint-0.9.0.8 · Hint.BaseThe installed version of ghc is not thread-safe. This exception
is thrown whenever you try to execute runInterpreter while another
instance is already running.
Show MultipleInstancesNotAllowedDefined in hint-0.9.0.8 · Hint.InterpreterTException MultipleInstancesNotAllowedDefined in hint-0.9.0.8 · Hint.InterpreterTVersion of the underlying ghc api. Values are:
804 for GHC 8.4.x
806 for GHC 8.6.x
etc...
Conceptually, parens s = "(" ++ s ++ ")", where s is any valid haskell
expression. In practice, it is harder than this.
Observe that if s ends with a trailing comment, then parens s would
be a malformed expression. The straightforward solution for this is to
put the closing parenthesis in a different line. However, now we are
messing with the layout rules and we don't know where s is going to
be used!
Solution: parens s = "(let {foo =\n" ++ s ++ "\n ;} in foo)" where foo does not occur in s
class (forall (m :: Type -> Type). Monad m => Monad (t m)) => MonadTrans (t :: (Type -> Type) -> Type -> Type) whereThe class of monad transformers.
For any monad m, the result t m should also be a monad,
and lift should be a monad transformation from m to t m,
i.e. it should satisfy the following laws:
Since 0.6.0.0 and for GHC 8.6 and later, the requirement that t m
be a Monad is enforced by the implication constraint
forall m. Monad m => Monad (t m) enabled by the
QuantifiedConstraints extension.
These versions of GHC have a bug (https://gitlab.haskell.org/ghc/ghc/-/issues/20582) which causes constraints like
(MonadTrans t, forall m. Monad m => Monad (t m)) => ...
to be reported as ambiguous. For transformers 0.6 and later, this can be fixed by removing the second constraint, which is implied by the first.
MonadTrans CatchTDefined in exceptions-0.10.9 · Control.Monad.Catch.PureMonadTrans ZonkTDefined in ghc-9.10.3 · GHC.Tc.Zonk.EnvMonadTrans CodensityDefined in ghc-9.10.3 · GHC.Utils.Monad.CodensityMonadTrans GhcTDefined in hint-0.9.0.8 · Control.Monad.GhcMonadTrans InterpreterTDefined in hint-0.9.0.8 · Hint.InterpreterTMonadTrans MaybeTDefined in transformers-0.6.1.1 · Control.Monad.Trans.MaybeMonoid w => MonadTrans (AccumT w)Defined in transformers-0.6.1.1 · Control.Monad.Trans.AccumMonoid w => MonadTrans (WriterT w)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.LazyMonoid w => MonadTrans (WriterT w)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.StrictMonadTrans IdentityTDefined in transformers-0.6.1.1 · Control.Monad.Trans.IdentityMonadTrans (ExceptT e)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ExceptMonadTrans (ReaderT r)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ReaderMonadTrans (SelectT r)Defined in transformers-0.6.1.1 · Control.Monad.Trans.SelectMonadTrans (StateT s)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.LazyMonadTrans (StateT s)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.StrictMonadTrans (WriterT w)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPSMonadTrans (ContT r)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ContMonoid w => MonadTrans (RWST r w s)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.LazyMonoid w => MonadTrans (RWST r w s)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.StrictMonadTrans (RWST r w s)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.CPSMonads in which IO computations may be embedded. Any monad built by applying a sequence of monad transformers to the IO monad will be an instance of this class.
Instances should satisfy the following laws, which state that liftIO is a transformer of monads:
liftIO :: IO a -> m aLift a computation from the IO monad. This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations (i.e. IO is the base monad for the stack).
import Control.Monad.Trans.State -- from the "transformers" library
printState :: Show s => StateT s IO ()
printState = do
state <- get
liftIO $ print stateHad we omitted liftIO, we would have ended up with this error:
• Couldn't match type ‘IO’ with ‘StateT s IO’
Expected type: StateT s IO ()
Actual type: IO ()The important part here is the mismatch between StateT s IO () and IO ().
Luckily, we know of a function that takes an IO a and returns an (m a): liftIO,
enabling us to run the program and see the expected results:
> evalStateT printState "hello"
"hello"
> evalStateT printState 3
3
MonadIO CoreMDefined in ghc-9.10.3 · GHC.Core.Opt.MonadMonadIO SimplMDefined in ghc-9.10.3 · GHC.Core.Opt.Simplify.MonadMonadIO HscDefined in ghc-9.10.3 · GHC.Driver.Env.TypesMonadIO GhcDefined in ghc-9.10.3 · GHC.Driver.MonadMonadIO HookedUseDefined in ghc-9.10.3 · GHC.Driver.Pipeline.ExecuteMonadIO StgMDefined in ghc-9.10.3 · GHC.Stg.PipelineMonadIO TcSDefined in ghc-9.10.3 · GHC.Tc.Solver.MonadMonadIO ZonkMDefined in ghc-9.10.3 · GHC.Tc.Zonk.MonadMonadIO IODefined in base-4.20.2.0 · Control.Monad.IO.ClassMonadIO GHCiQDefined in ghci-9.10.3 · GHCi.THMonadIO QDefined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxMonadIO (IOEnv env)Defined in ghc-9.10.3 · GHC.Data.IOEnvMonadIO m => MonadIO (CatchT m)Defined in exceptions-0.10.9 · Control.Monad.Catch.PureMonadIO m => MonadIO (EwM m)Defined in ghc-9.10.3 · GHC.Driver.CmdLineMonadIO m => MonadIO (GhcT m)Defined in ghc-9.10.3 · GHC.Driver.MonadMonadIO m => MonadIO (ZonkBndrT m)Defined in ghc-9.10.3 · GHC.Tc.Zonk.EnvMonadIO m => MonadIO (ZonkT m)Defined in ghc-9.10.3 · GHC.Tc.Zonk.EnvMonadIO m => MonadIO (Codensity m)Defined in ghc-9.10.3 · GHC.Utils.Monad.CodensityMonadIO m => MonadIO (GhcT m)Defined in hint-0.9.0.8 · Control.Monad.GhcMonadIO m => MonadIO (MTLAdapter m)Defined in hint-0.9.0.8 · Control.Monad.GhcMonadIO m => MonadIO (InterpreterT m)Defined in hint-0.9.0.8 · Hint.InterpreterTMonadIO m => MonadIO (MaybeT m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.MaybeMonadIO m => MonadIO (Stream m b)Defined in ghc-9.10.3 · GHC.Data.StreamMonadIO m => MonadIO (ExceptT e m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ExceptMonadIO m => MonadIO (IdentityT m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.IdentityMonadIO m => MonadIO (ReaderT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ReaderMonadIO m => MonadIO (SelectT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.SelectMonadIO m => MonadIO (StateT s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.LazyMonadIO m => MonadIO (StateT s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.State.StrictMonadIO m => MonadIO (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.CPS(Monoid w, MonadIO m) => MonadIO (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Lazy(Monoid w, MonadIO m) => MonadIO (WriterT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.Writer.Strict(Monoid w, Functor m, MonadIO m) => MonadIO (AccumT w m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.AccumMonadIO m => MonadIO (ContT r m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.ContMonadIO m => MonadIO (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.CPS(Monoid w, MonadIO m) => MonadIO (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.Lazy(Monoid w, MonadIO m) => MonadIO (RWST r w s m)Defined in transformers-0.6.1.1 · Control.Monad.Trans.RWS.Strict