Is interpret used to eval haskell expression ? if so, how can i use it?
Language.Haskell.Interpreter> :t interpret
interpret :: (Data.Typeable.Internal.Typeable a, MonadInterpreter m) =>
String -> a -> m a
>interpret "1+1"
<interactive>:20:1:
Ambiguous type variable `m0' in the constraint:
(MonadInterpreter m0) arising from a use of `interpret'
Probable fix: add a type signature that fixes these type variable(s)
In the expression: interpret "1+1"
In an equation for `it': it = interpret "1+1"
Regards!
There are some examples here:
where “Convenience functions to be used with interpret to provide witnesses”:
P.S.
API of
Language.Haskell.Interpreteris not very user-friendly. Without inspecting its example files its usage would be a conundrum for me (not an advanced Haskeller).But with the help of an example here we go:
The helpful example file can be found in
~/.cabal/packages/hackage.haskell.org/hint/0.3.3.5/hint-0.3.3.5.tar.gz.It looks like
interpretmust be run inside a monad constrained byMonadInterpreter m:IO clearly does not have an instance for
MonadInterpreterclass, hence the error. This is an expected behaviour, sinceIOmonad of GHCI does not have required information about the interpreter session. A proper monad type must be set byrunInterpreter.