PolyChrome
PolyChrome is an extension for Firefox web browser that can run Standard ML programs embedded in HTML documents. The extension provides a simple foreign function interface to JavaScript. As a result, JavaScript libraries and interfaces provided by the browser, such as DOM and Canvas, can be used from Standard ML.
Why do this?
- HTML, CSS and browser technologies such as Canvas or Scalabble Vector Graphics support provide Standard ML with a way of creating Graphical User Interfaces or graphics in general.
- Easy deployment of SML applications. If PolyML and PolyChrome is installed, opening the URL (remote or local) of the application is all it takes to run it.
- Cross-platform GUIs (Although Windows is currently not tested and probably requires cygwin).
What are the limitations?
- The JavaScript FFI is rather inefficient therefore applications using this FFI intensively, e.g. rendering animations, might be slow.
- The memory sharing mechanism between JavaScript and Standard ML is not fully automated, which means that some explicit code for memory management is sometimes needed (to prevent memory leaks).
- All ML applications are currently trusted, they could potentially be harmful: we do not currently limit what SML can do on the client machine.
How does it work?
- PolyChrome is composed of two main components. The JavaScript component of the extension (executed in Firefox) opens up a PolyML process, which we call the ML component, for each HTML document.
- A socket connection is established between the JavaScript and Standard ML components.
- DOM, Canvas, etc. libraries are loaded in PolyML.
- Those libraries use the socket connection to forward any JavaScript function call to the JavaScript component, where it get's executed.
- Because the browser provides a JavaScript interface to DOM, we can now access and modify DOM from Standard ML code.
- The SML code from the HTML document is grabbed by the JavaScript component and sent for evaluation to the Standard ML component
- More details are provided in the documentation
PolyChrome in action
About the Project
PolyChrome was developed by Karolis Narkevicius and Lucas Dixon. We'd like to thank EPSRC Platform grant The Integration and Interaction of Multiple Mathematical Reasoning Processes", and the Edinburgh DReaM group for supporting this work. We'd also like to thank David Matthews for his input, ML wizardry, and tireless maintenance of PolyML.