The Azimuth Project
Experiments in the Fay EDSL for Javascript (Rev #5)


An attempt at a simplest possible functional programming syntax for simulation model specification using the Fay embedded domain specific language (EDSL) and Javascript compiler.

The following code snippets are under test and might provide a basis for a first FSim.hs. They have mostly been lifted directly from other people’s code in Haskell or ported from other languages.


  • Matrix operations
  • Fourier transform (inverse missing)
  • Euler’s method
  • RK4
  • Crank-Nicholson method
  • Kalman filter
  • Circuits
  • Onsager
  • misc.


  • Ring oscillator
  • Zero-dimension energy balance model (EBM)
  • One-dimensional EBM
  • Kamp advective ocean model
  • Game of Life
  • misc.

Ring oscillator

Ian Ross’s “Fun with Fay” is a literate blog post using Fay and html5 canvas and a timer to display an animated 5 ring oscillator with dynamic graphs.

This seemed like a good example to start with but is too complicated for describing simple simulations.

The stripped-out user interfaceses html5 Options for parameter values. This avoids the FF non-working html5 slider problem.

Work is in progress on the simulation function (loop step? iterate step?) and graph rendering etc.

He also has another blog post on creating a good-looking jquery slider. Unfortunately this is for the Yesod web framework and needs to be ported to Snap TBD.

Zero-Dimension EBM

I have no idea where these parameters came from, it’s merely for illustrative purposes.

In the Fay proper subset of Haskell

testCO2 = temp 4.3

temp f = (-f)/totalF where

lambda0 = 3.2 :: Double -- Plank

totalF = avLambda - lambda0

avLambda = (maxSumF - minSumF)/2

minSumF = foldl (+) 0 (fmap fst lambda)

maxSumF = foldl (+) 0 (fmap snd lambda)

lambda = [waterVapour,lapseRate,clouds,albedo]

waterVapour = (1.48,2.14)

lapseRate = (-0.41,-1.27)

clouds = (0.18,1.18)

albedo = (0.07,0.34)

The resulting Javascript.

This is supposed to be literate code so you should be able to cut and paste it into a text editor, save it as

<filename>.js and run it with node.js, ie.</filename>

` node <filename>.js

and get an answer of ~1.6 deg. C.