Types and Functions in mondrian.lang

Operators

(-) : Integer -> Integer;
(-) : Double -> Double;

(-) : Integer -> Integer -> Integer;
(-) : Double -> Double -> Double;

(+) : Integer -> Integer -> Integer;
(+) : Double -> Double -> Double;
(+) : String -> String -> String;

(*) : Integer -> Integer -> Integer;
(*) : Double -> Double -> Double;

(/) : Integer -> Integer -> Integer;
(/) : Double -> Double -> Double;

(%) : Integer -> Integer -> Integer;

(<) : Integer -> Integer -> Boolean;
(<) : Double -> Double -> Boolean;

(>) : Integer -> Integer -> Boolean;
(>) : Double -> Double -> Boolean;

(<=) : Integer -> Integer -> Boolean;
(<=) : Double -> Double -> Boolean;

(>=) : Integer -> Integer -> Boolean;
(>=) : Double -> Double -> Boolean;

(&&) : Boolean -> Boolean -> Boolean;
(||) : Boolean -> Boolean -> Boolean;

(==) : a -> a -> Boolean;
(!=) : a -> a -> Boolean;

All have the usual meanings, + is also string concatenation. (In)equality does the right thing, same value for basic types, object Equals method for other types.

Conversion

ord : Character -> Integer;
chr : Integer -> Character;

show : a -> String;

Calls the toString/ToString method on the object.

stringToList : String -> List Character;
listToString : List Character -> String;

As String is an underlying platform type these functions do a complete conversion before returning, you can’t have a partially evaluated String.

arrayToList : Array a -> List a;
listToArray : List a -> Array a;

As Array is an underlying platform type these functions do a complete conversion before returning, you can’t have a partially evaluated array.

listToIntArray : List Integer -> Array Int32;

This is a special function for a common case. listToArray will return an array of reference values, that is for primitive values such as integers the values will be boxed. listToIntArray returns an array of unboxed integers.

Lists

class List;
class Nil extends List;
class Cons extends List
{ head : a;
  tail : List a;
};

Nil can also be written [], Cons as ::, and [a, b, ..., n] has the usual meaning. Though other platform languages can access the fields of a Cons this is unadvisable as they may contain yet-to-be-evaluated values, use hd and tl in mondrian.prelude instead.

listStringEq : List Char -> String -> Boolean;

Compares whether a list of characters and a string have the same value.

Evaluation

seq : a -> b -> b;
strict : a -> b -> b;

The seq function evaluates its first argument to WHNF and then returns its second argument. The strict function is similar but evaluates to normal form.

Exceptions

class PatternMathingException extends RuntimeException;

This exception is thrown when a pattern matching error occurs, i.e. when there is no matching case in a switch.

evalAndCatch : a -> a -> a;

Evaluates its first argument to normal form and returns it unless an exception occurs in which case it returns its second argument.

IO Monad

bind : IO a -> (a -> IO b) -> IO b;
result : a -> IO a;

The bind function is used by the do expression:

a ; b == bind a (ignore -> b)
b <- a ; c == bind a (b -> c)

unsafePerformIO : IO a -> a;

Perform I/O NOW!

Variables

createVar : a -> IO (Var a);
setVar : Var a -> a -> IO Void;
getVar : Var a -> IO a;

Create, set and get a variable. Variables can be used to communicate between threads.

class Var
{ Var (Object);
  Object getValue();
  void setValue(Object);
};

This is the type of variables as seen by other JVM/.NET languages. Other languages should lock a variable before accessing it, and use wait/notify/notifyAll/pulse/pulseAll as appropriate to synchronize with Mondrian

wait : Var a -> IO Void;
notify : Var a -> IO Void;
notifyAll : Var a -> IO Void;

Same semantics as in JVM/.NET.

I/O

ConsoleIn : ReadHandle;
ConsoleOut : WriteHandle;
ConsoleError: WriteHandle;

Standard channels. In .NET a ReadHandle is a TextReader and a WriteHandle is a TextWriter.

putChar : Character -> IO Void;
putStr : String -> IO Void;
putStrLn : String -> IO Void;
putLine : IO Void;

putLine outputs a newline

getChar : IO Character;
getLine : IO String;

openOutputFile : String -> IO WriteHandle;
appendOutputFIle : String -> IO WriteHandle;
openInputFile : String -> IO ReadHandle;

Open files, only text files are supported.

hPutChar : WriteHandle -> Character -> IO Void;
hPutStr : WriteHandle -> String -> IO Void;
hPutStrLn : WriteHandle -> String -> IO Void;
hPutLine : WriteHandle -> IO Void;

hGetChar : ReadHandle -> IO Character;
hGetLine : ReadHandle -> IO String;

fileClose : WriteHandle -> IO Void;
fileClose : ReadHandle -> IO Void;

These are actually the same function... Now you know why we don’t have a well defined type system yet!

Last modified: 15/10/2001