We are submitting an implementation of a compiler extension for static values following the outline of . This work was developed with the support of Tweag I/O.
The extension introduces a new syntactic form (static e), where e :: a can be any closed expression. The static form produces a value of type Ref a, which works as a reference that programs can "dereference" to get the value of e back. References are like Ptrs, except that they are stable across invocations of a program.
While the body of the static form may not have a direct serializable representation, references of type Ref uniquely identify it, can be serialized and meaningfully transmitted across a network.
The implementation of a Ref contains information that is useful to locate the referenced value in symbol tables of libraries and object files. While static e is a baked in syntactic form, resolving (dereferencing) references to values is implemented entirely in userland, as a library function (i.e. what would correspond to unstatic as formulated in ). We provide a basic implementation of lookups in the module GHC.Ref of the base package.
In essence the extension makes sure that the argument of the static form does appear in linker symbol tables, and it fills in the information carried by references (package name, installation identifier, module name, symbol name). For more details we refer to the users guide section contained in the patch.
The extension is a contribution to the Cloud Haskell ecosystem (distributed-process and related), and thus has the potential to foster Haskell as a programming language for distributed systems.
The immediate improvement brought by the extension is the elimination of remote tables from Cloud Haskell applications. Such applications contain table fragments spread throughout multiple modules and packages. Eliminating these tables saves the programmer the burden required to construct and assemble the global remote table from fragments, a verbose and error-prone process, even with the help of Template Haskell, that moreover pollutes the export lists of all modules.
As a nice convenience, the extension implemented here makes it possible to write shorter code by allowing any closed expression as argument of the static form, not just single identifiers the way Cloud Haskell currently requires .
In the future, the extension could open the door for implementing a form of sending code between the members of a distributed application in the form of libraries or object files.
A notable limitation of the extension is that it cannot create references to values with qualified types. Thus, static show is an illegal term because show has a constraint Show a in its type. For the time being, this limitation can be sidestepped as explained in the contributed documentation to the user’s guide.
Comments and suggestions will be much appreciated.
It has been pointed out that “static values” is probably not the best name for this extension. And we mostly agree. By default, we’re using the name from the original paper and would like to get this proposal to a strong technical basis first. But here are a few alternative names that have shown up:
- -XStaticPtr and have Ref be named StaticPtr. A StaticPtr is a StablePtr that’s so stable it’s portable across different processes.
- -XStaticNames (carter)
- -XPinnedPointers (hvr)
 Jeff Epstein, Andrew P. Black, and Simon Peyton-Jones. Towards Haskell in the cloud. SIGPLAN Not., 46(12):118–129, September 2011. ISSN 0362-1340.