Eval in Haskell

oleg@pobox.com oleg@pobox.com
Fri, 30 May 2003 19:57:57 -0700 (PDT)


Simon Marlow wrote:

> The test driver makes use of 'eval'-style scripting, which none of the
> existing Haskell systems has.

Doesn't the following qualify as eval? A similar code works even in
Hugs.

> import System (system, ExitCode(ExitSuccess))
> import Posix(executeFile)
>
> myconfig_file = "/tmp/config"
>
> phaseII_var = "/tmp/Config.hs"
> phaseII_const = "/tmp/a.hs"
> phaseII_eval = "ghc --make "
> phaseII_result = "/tmp/a.out"
>
> nl = "\n"
>
> writeConfig :: Int -> IO ()
> writeConfig num =
>   do
>    writeFile phaseII_var $
>         concat
>          ["module Config (config_item) where", nl,
>           "config_item =", show num, nl]
>  
>
> runSuperIO () = system (phaseII_eval ++ 
>                         phaseII_const ++ " -o " ++ phaseII_result)
>                 >>= \ExitSuccess -> 
>                          executeFile phaseII_result False [] Nothing
>
> main = readFile myconfig_file >>= writeConfig . read >>= runSuperIO

The context:
http://www.haskell.org/pipermail/haskell-cafe/2003-February/003912.html

Furthermore, if GHCi can (after some prodding by the user) launch ghc
to compile a module and then load the resulting .o file in and
apply some function in thus loaded file, doesn't it feel like an eval?