GHCi turned upside down?

George Russell
Fri, 11 May 2001 15:22:31 +0200

GHCi allows us to mix fixed compiled and dynamic interpreted code to 
be run from what I presume is dynamic interpreted code - the command
prompt.  Would it be possible to run dynamic interpreted code from
a compiled program?  I'm hoping the answer is "Yes, because this is what
GHCi does", the only problem being to clean up the syntax and document

I'm afraid I haven't been following the FFI debate lately but perhaps we
could steal some of the FFI's syntax for declaring types of imported
entities.  The difference (I'm not sure if this is a difference with
the latest with the latest FFI version) would be that the source file/string
(and perhaps function name) need to vary dynamically, which means also that
of course it needs to be done below top level, and invoke an IO action.  So
we might try something like

runMain :: FilePath -> IO ()
runMain sourcePath =
      source <- readFile sourcePath
      foreign import ghci source "main" main :: IO ()

which would read the file "sourcePath", interpret it as Haskell,
and run the "main" action therein.

This isn't meant to be a polished proposal, just an idea for something
which might be nice to have around in the future.