Abstract
We present a solution to the problem of dynamic extension in statically
typed functional languages with type erasure. The presented solution
retains the benefits of static checking, including type safety,
aggressive optimizations, and native code compilation of components,
while allowing extensibility of programs at runtime.
Our approach is based on a framework for dynamic extension in a
statically typed setting, combining dynamic linking, runtime type
checking, first class modules and code hot swapping. We show that this
framework is sufficient to allow a broad class of dynamic extension
capabilities in any statically typed functional language with type
erasure semantics.
Uniquely, we employ the full compile-time type system to perform runtime
type checking of dynamic components, and emphasize the use of native
code extension to ensure that the performance benefits of static typing
are retained in a dynamic environment. We also develop the concept of
fully dynamic software architectures, where the static core is
minimal and all code is hot swappable. Benefits of the approach include
hot swappable code and sophisticated application extension via embedded
domain specific languages.
We instantiate the concepts of the framework via a full implementation
in the Haskell programming language: providing rich mechanisms for
dynamic linking, loading, hot swapping, and runtime type checking in
Haskell for the first time. We demonstrate the feasibility of this
architecture through a number of novel applications: an extensible text
editor; a plugin-based network chat bot; a simulator for polymer
chemistry; and xmonad, an extensible window manager. In doing so, we
demonstrate that static typing is no barrier to dynamic extension.