snap-loader-dynamic- Snap: A Haskell Web Framework: dynamic loader

Safe HaskellNone



This module includes the machinery necessary to use hint to load action code dynamically. It includes a Template Haskell function to gather the necessary compile-time information about code location, compiler arguments, etc, and bind that information into the calls to the dynamic loader.





:: Q Exp

the initializer expression

-> Name

the name of the load function

-> [String]

a list of directories to watch in addition to those containing code

-> Q Exp 

This function derives all the information necessary to use the interpreter from the compile-time environment, and compiles it in to the generated code.

This could be considered a TH wrapper around a function

 loadSnap :: Typeable a => IO a -> (a -> IO (Snap (), IO ()))
                        -> [String] -> IO (a, Snap (), IO ())

with a magical implementation. The [String] argument is a list of directories to watch for updates to trigger a reloading. Directories containing code should be automatically picked up by this splice.

The generated splice executes the initialiser once, sets up the interpreter for the load function, and returns the initializer's result along with the interpreter's proxy handler and cleanup actions. The behavior of the proxy actions will change to reflect changes in the watched files, reinterpreting the load function as needed and applying it to the initializer result.

This will handle reloading the application successfully in most cases. The cases in which it is certain to fail are those involving changing the types of the initializer or the load function, or changing the compiler options required, such as by changing/adding dependencies in the project's .cabal file. In those cases, a full recompile will be needed.