A Brief Introduction to Mondrian


Mondrian [4, 5] is a new functional language specifically designed to fit well into object-oriented virtual machine environments, such as the .NET Framework. The semantics of the language will be familiar to functional-language programmers: It is a simple, nonstrict language. The I/O system is based on monads [6] and follows the design of Haskell [2]. A number of things are unusual, however, including the type system, exception handling, concurrency support, and syntax.

The Type System

The type system is based on those used by object-oriented languages, with the addition of parametric polymorphism. This type system makes Mondrian rather different from traditional functional languages. While it retains the expressive power, it is more easily accessible through interlanguage calling to other languages executing under the .NET Framework. Discussion of the type system from the programmer's perspective forms the major part of this appendix.

Some of the ideas in Mondrian can be seen in earlier language designs such as Pizza [7] and GJ [8] for Java, and Generic C# [9] for the .NET Framework. These language designs all extend an underlying object-oriented language by introducing concepts more common in functional languages. Mondrian takes an different approach ”it is a functional design adapted for an object-oriented environment.

Exception Handling

Exceptions are an integral part of the CLR and are the standard method through which routines in the .NET Framework report and handle errors. Mondrian provides proper support for such exceptions. Constructs are provided both to generate and to handle exceptions: Exceptions produced by other CLR-hosted language code called from Mondrian can be caught, and other languages calling Mondrian can catch its exceptions.

Mondrian is not the first example of a functional language with exception handling. For example, exception handling has been added to Haskell [10]. Nevertheless, Mondrian is unusual in its complete integration with an exception system provided by an object-oriented virtual machine environment.

Concurrency Support

Threads and synchronization primitives are also an integral part of the CLR and .NET Framework. Following on from our previous work, such as Concurrent Hope + C [11], Mondrian provides full support for CLR threads and synchronization primitives. In a multithreaded program, the individual threads can be written in any CLR-hosted language, including Mondrian, and synchronize with, and pass data between, one another.

The Syntax

The syntax of Mondrian is unusual in that it looks more like C# and less like traditional functional languages. This design was chosen to make the language more accessible to object-oriented programmers keen to exploit the expressive power of functional languages through interlanguage calling from imperative object-oriented code.

Mondrian is also a minimalist language, [1] rarely providing two ways of doing something, and often providing simpler expression forms than current functional languages offer. For example, although Mondrian supports pattern matching, a cornerstone of most functional languages, only a single level of data can be matched at a time.

[1] The language is named after the Dutch abstract painter Pieter Cornelis Mondrian (1872 “1944). In his later work, Mondrian limited himself to small vertical and horizontal strokes.

To give an idea of how Mondrian looks, Listing G.1 is a simple function that calculates the roots of the quadratic equation ax 2 + bx + c = 0.

Listing G.1
 class Pair { r1 : Double; r2 : Double; } roots : Double -> Double -> Double -> Pair; roots = a -> b -> c    let       d    = b * b - 4 * a * c;       root = sqrt d;       a2   = 2 * a;    in if d < 0       then          Pair(-1, -1)       else          Pair( (-b + root)/a2, (-b - root)/a2 ); 


Programming in the .NET Environment
Programming in the .NET Environment
ISBN: 0201770180
EAN: 2147483647
Year: 2002
Pages: 146

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net