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

Showing changes from revision #4 to #5: Added | Removed | Changed


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

For The want following of code snippets are under test and might provide a better basis starting for place, here is a mystery first 5 FSim.hs. minute They example have of mostly what been looks lifted like directly Zero-Dimension from EBM other people’s code which in I Haskell found or I’d ported written from more other than languages. a year ago.


  • 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

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.

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.