Sample Programs

These are found in sub-directories of the sample directory. Before running any of the samples or compilers execute the shell.bat file to open a command line shell with the environment set appropriately. The samples are:

hello

A simple “hello world” style Mondrian program. To compile and run:

mdc hello.ms
hello

primes 1

A program to generate primes. This shows how functional languages allow a different approach to problems. Rather than solving the standard prime sieve problem “find all primes less than N” this program solves “find the Nth prime’ - a task rather more difficult in, say, C#.

The sample also shows how to call a C# method from Mondrian.

To compile and run:

mdc sieve.ms
sieve

primes 2

The ease of inter-language working is one of the key features of .NET allowing the strengths of different languages to be combined. This version of primes uses Mondrian to compute the primes and C# to handle the I/O. To compile and run:

mdc main.cs sieve.ms
main

primes 3

The primes problem solved in Haskell. To compile an run:

monghc sieve.hs
mondrian sieve.mc
hcs sieve.cs
main

cse

This is a Haskell example taken from the “no fib” suite of testing programs, it performs common sub-expression elimination on trees. To compile and run:

monghc StateMonad.hs
monghc Main.hs
mondrian *.mc
hcs *.cs
main

Dining Philosophers

This is a animation of the Dining Philosophers problem from concurrent programming. It demostrates Mondrian & C# threads interworking. C# is used to produce and drive a WinForms interface, Mondrian runs the concurrent alogorithm. Events initiall are passed to C# handlers which then called handlers in Mondrian to adjust the alogrithm parameters.You can even hear the Philosophers eating!

The program is based on a version distributed for Java.

To compile and run:

mdc *.ms *.cs
DiningPhilosophers

Last modified: 15/10/2001