plugins-auto

Automatic recompilation and reloading of haskell modules.

Latest on Hackage:0.0.4

This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.

BSD-3-Clause licensed by Happstack team, HAppS LLC and MarketPsych Advisor LLC
Maintained by Happstack team

This library provides support for automatically recompiling and reloading modules into your programs when the source code is modified.

Any program called ghc in your PATH will be used for recompiling.

module Main where
import System.IO           (hSetBuffering,stdout,BufferMode(..))
import System.Plugins.Auto (withMonadIO,initPlugins)
import Answer

main :: IO ()
main = do ph<-initPlugins
        hSetBuffering stdout NoBuffering
        putStrLn "This program interacts with you in a loop."
        putStrLn "Type something, and the program will respond when you hit the Enter Key."
        putStrLn "Modify Answer.hs while interacting and you should see the answers"
        putStrLn "change accordingly."
        let interactiveLoop = prompt ph >> interactiveLoop
        interactiveLoop
where
  prompt ph = do
     putStr "> "
     input <- getLine
     $(withMonadIO 'getAnswer) ph notLoaded$ \errs getAnswer ->
         mapM_ putStrLn errs  >> getAnswer input

  notLoaded errs =
     if null errs then putStrLn "Plugin not loaded yet."
       else putStrLn "Errors found:" >> mapM_ (putStrLn . ("  "++)) errs
              >> putStrLn "Try fixing the errors and come back here."
module Answer where

getAnswer :: String -> IO ()
getAnswer input = putStrLn ("What you typed: "++input)