hint icon indicating copy to clipboard operation
hint copied to clipboard

Can't use identifiers from loaded modules

Open brandon-leapyear opened this issue 3 years ago • 1 comments

Minimal repro:

  1. Write a file Foo.hs like

    module Foo where
    
    x :: Int
    x = 1
    
  2. Run stack ghci --package hint, then in the shell, do:

    import qualified Language.Haskell.Interpreter.Hint
    import Control.Monad.IO.Class
    Hint.runInterpreter $ do { Hint.loadModules ["Foo.hs"]; liftIO . print =<< Hint.getModuleExports "Foo"; Hint.eval "x" }
    

The output I see is:

[Fun "x"]
Left (WontCompile [GhcError {errMsg = "<interactive>:3:1: error: Variable not in scope: x"}])

which shows that x was loaded, but evaluating it doesn't work. Same thing happens with other functions like typeOf

brandon-leapyear avatar Oct 02 '20 22:10 brandon-leapyear

:sparkles: This is an old work account. Please reference @brandonchinn178 for all future communication :sparkles:


Ah I guess I have to do

loadModules ["Foo.hs"]
setTopLevelModules ["Foo"]
eval "x"

is that intended? If so, the docs could clarify what the difference between loadModules and setTopLevelModules intends

brandon-leapyear avatar Oct 02 '20 22:10 brandon-leapyear

I have clarified the behaviour of loadModules in the documentation, which will be updated in the next release.

gelisam avatar Jun 15 '23 04:06 gelisam

Here is the updated documentation: https://github.com/haskell-hint/hint/pull/160/files#diff-e54c923347aee61efe6f22a52e9d2f061feaf554ef594a2e1a430f7da639306aR190-R193

gelisam avatar Jun 15 '23 04:06 gelisam