-
Notifications
You must be signed in to change notification settings - Fork 42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Ability to use data
and newtype
?
#171
Comments
Alas, ghci is smarter. it first parses the input line to check if ghci doesn't support parsing a string into a module yet, so you'll have to do it the old fashioned way, by loading it from a file: import Language.Haskell.Interpreter
-- |
-- >>> main
-- Right 6
main :: IO ()
main = do
writeFile "MyModule.hs"
"module MyModule where\n\
\data MyBool = MyTrue | MyFalse deriving Show\n\
\"
r <- runInterpreter $ do
loadModules ["MyModule.hs"]
setImports ["Prelude", "MyModule"]
interpret "length (show MyTrue)" (as :: Int)
print r hint's implementation actually has some machinery called "phantom modules" for creating and loading anonymous modules by saving them to temporary files, so I don't think it would be too hard to automate the above trick and to expose it as a function which loads a module defined by a string rather than by a filename. But now that ghc supports loading modules from strings, it would be more elegant to get rid of phantom modules and to use that functionality directly. And then to do the same thing ghci does for loading declarations. |
After looking at the runDecls :: MonadInterpreter m => String -> m ()
runDecls s = runGhc $ void $ GHC.runDecls s Obviously it would need to be wrapped in |
Hello, I came across this limitation and was able to code a mechanism that allows this by exposing a function that installs phantom modules. I'm motivated to contribute this back into the package but I need some clarification on what the solution should be. Have we made any advances with migrating to |
I may be missing something, but is it possible to declare new datatypes? For example, I tried
runStmt "data MyBool = MyTrue | MyFalse"
, but I get:Is there any way to do this or any work around to do this?
The text was updated successfully, but these errors were encountered: