impure — Impure functions

This module provides functions which break the declarative semantics of Mars.


Mars is, fundamentally, a pure language. This means that no function can modify an existing value or global state, only return a value (and perform input/output, which while technically impure, isn’t considered “impure” in Mars).

The functions in this module break that purity by modifying their input arguments. They should not be considered part of the language semantics, and are not intended to be used by most code. They are provided to increase performance in certain situations. Use at your own risk.

Comparison functions

is(x :: a, y :: a) :: Int

Returns 1 if x has the same identity as y, 0 otherwise. This performs “reference” equality, such that two values are only considered equal if they are the same object or are directly aliased. If the values are integers, this is the same as eq. It is an error if the values are function objects.

This function breaks the pure semantics of the Mars programming language because in a pure language, it should not be possible to distinguish between two aliased objects and two unaliased objects which are equal.

Array operations

These functions apply an operation to all values which are aliased to the input array (for which is compares true).

array_set(array :: Array(a), index :: Int, value :: a) :: Array(a)

Replaces array element index with value. Returns array. It is an error if array has no element at index.

array_append(array :: Array(a), value :: a) :: Array(a)

Appends value onto the end of array. Returns array.

array_extend(array1 :: Array(a), array2 :: Array(a)) :: Array(a)

Appends each element of array2 onto the end of array1. Does not modify array2. Returns array1.

array_delete(array :: Array(a), index :: Int) :: Array(a)

Removes array element index. Returns array. It is an error if array has no element at index.

Table Of Contents

Previous topic

prelude — Common functions

Next topic

unittest — Testing user code

This Page