Skip to content


Subversion checkout URL

You can clone with
Download ZIP
example package for class at BayHac 2014 on development with the Haste compiler
Haskell JavaScript CSS
Fetching latest commit...
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

This package contains code for an example Web application for a class at BayHac2014. The application allows to create encrypted emails from within a browser.

This is not production level code.

The purpose of this package to demonstrate techniques for development of portable Haskell libraries that can be used with native compilations as well as cross-compilations to client-side javascript via the Haste compiler.



The package includes a library component that can be compiled with native GHC as well as with the Haste compiler. The library exposes two interfaces:

  1. a Haskell API for encryption and decryption with a password and
  2. a JSON service API that wraps the Haskell API in JSON data types.

The package further contains an application that serves the JSON API over HTTP using scotty.

The package also contains an application that exports the JSON API as client side javascript module.

Finally, there is a cabal test suite for unit testing the library with a native compilation.

Setup of Haste with a Sandbox

The following instructions installs the haste-compiler in a cabal sandbox. Note, however, that the resulting haste-compiler itself is not using a sandbox for compilations.

Build Haste:

cabal sandbox init
echo 'constraints: scientific<0.3' >> cabal.config
cabal install haste-compiler -j
export PATH=./.cabal-sandbox/bin:$PATH

Setup Haste:

echo 'solver: topdown' >> ~/.cabal/config
sed -i '/solver: topdown/d' ~/.cabal/config

If haste-boot failes with an error message that inlcude the text only already installed instances can be used you may try to temporarily add the following to your ~/.cabal/config while running haste-boot.


The native version of the library and the server application can be installed via

cabal install

The test suite can be run via

cabal configure --enable-tests
cabal build
cabal test

The javascript module is build via

mv cabal.sandbox.config cabal.sandbox.config.disabled
haste-inst install -fhaste
haste-inst configure -fhaste
haste-inst build

The resulting javascript code is in the file src/Client.js. It can be tested by opening the file Main.html in a browser from the root directory of the package.

Legal Notes

This package includes a copy of a version of SJCL in the file ./lib/sjcl.js. SJCL is hosted at and distributed under a BSD license as described at

The file ./src/BayHac2014/Cryptmail/Json.hs and the files in the directory ./src/BayHac2014/Cryptmail/Json of this package in part contain code that was copied, derived, or inspired by the Aeson package. The Aeson package is distributed under a BSD3 License and copyright of (c) 2011-2014 Bryan O'Sullivan (c) 2011 MailRank, Inc.. A copy of the LICENSE of the Aeson package can be found here.

Something went wrong with that request. Please try again.