The prelude is where the most common functions are found. This module is typically imported by any Mars module. It is not imported by default, but if mars is run without any command-line arguments, this module will be loaded.
The identity function; returns x.
Returns a function which returns k, regardless of its argument.
Calls f with no arguments.
Calls f with x as an argument.
Calls f with x and y as arguments.
Converts f into a curried function – the resulting function takes one argument and returns a function that takes the second argument and calls f with both.
Converts f into a curried function – the resulting function takes one argument and returns a function that takes the second argument and so on, and calls f with all of the arguments.
Converts f into a curried function – the resulting function takes one argument and returns a function that takes the second argument and so on, and calls f with all of the arguments.
Creates a function which takes one argument and passes it to g, then passes the result of that to f.
Creates a function which passes its two arguments to f in the reverse order.
The Boolean AND of x and y. If x is nonzero, returns y; otherwise, returns 0.
Note
Mars doesn’t have a general tuple type. It just defines specific types for tuples of arity two, three and four.
Pair(a, b)
A pair of any two values.
Triple(a, b, c)
A sequence of any three values.
Quadruple(a, b, c, d)
A sequence of any four values.
Cons(head :: a, tail :: List(a))
Nil
A linked list of values, all of the same type. This type is incompatible with the Array type, but it is possible to convert between the two using list_to_array and array_to_list.
The list corresponding to all but first item in list. Aborts if list is empty.
The element of list with index index. The first element has index 0. It is an error if index is equal to or greater than the length of the list, or negative.
Applies function to each item in list, producing a new list containing each of the results. For example, map(f, array_to_list([a, b, c])) computes array_to_list([f(a), f(b), f(c)]).
Produces a new list containing only the items in list for which function returns a nonzero result.
Applies function to initial and the head of list, then to the result of that and the second element of list, and so on, returning the result of the final application. For example, foldl(f, z, array_to_list([a, b, c])) computes f(f(f(z, a), b), c).
foldl without an initial value. Applies function to the first and second elements of list, then to the result of that and the third element of list, and so on, returning the result of the final application. For example, foldl1(f, array_to_list([a, b, c, d])) computes f(f(f(a, b), c), d).
Applies function to the last element of list and initial, then to the second-last element of list and the result of that, and so on, returning the result of the final application. For example foldr(f, z, array_to_list([a, b, c])) computes f(a, f(b, f(c, z))).
foldr without an initial value. Applies function to the second-last and last elements of list, then to the third-last element and the result of that, and so on, returning the result of the final application. For example, foldr1(f, array_to_list([a, b, c, d])) computes f(a, f(b, f(c, d))).
Returns the elements of list1 concatenated onto the front of list2. Note that this operation is linear in the length of list1, but constant in the length of list2 (it makes a copy of list1 but not list2).
Returns the index of the first element of list which compares equal (according to eq) to item, or -1 if no element compares equal. The first element has index 0.
Returns 1 if any element of list compares equal (according to eq) to item; 0 otherwise.
Combine pairwise elements of list1 and list2 into a single list of pairs. For example, zip(array_to_list([a, b, c]), array_to_list([x, y, z])) produces array_to_list([Pair(a, x), Pair(b, y), Pair(c, z)]). If the two lists are not the same length, the resulting list is as long as the shorter list, with the remaining elements of the longer list discarded.
Separate a list of pairs into a pair of lists with corresponding elements of list. The first output list contains the fst of each element of list, and the second output list contains the snd of each element. For example, unzip(array_to_list([Pair(a, x), Pair(b, y), Pair(c, z)])) produces Pair(array_to_list([a, b, c]), array_to_list([x, y, z])).
Applies function to each item in array, producing a new array containing each of the results. For example, array_map(f, [a, b, c]) computes [f(a), f(b), f(c)].
Produces a new array containing only the items in array for which function returns a nonzero result.
Applies function to initial and the first element of array, then to the result of that and the second element of array, and so on, returning the result of the final application. For example, array_foldl(f, z, [a, b, c]) computes f(f(f(z, a), b), c).
array_foldl without an initial value. Applies function to the first and second elements of array, then to the result of that and the third element of array, and so on, returning the result of the final application. For example, array_foldl1(f, [a, b, c, d]) computes f(f(f(a, b), c), d).
Applies function to the last element of array and initial, then to the second-last element of array and the result of that, and so on, returning the result of the final application. For example array_foldr(f, z, [a, b, c]) computes f(a, f(b, f(c, z))).
array_foldr without an initial value. Applies function to the second-last and last elements of array, then to the third-last element and the result of that, and so on, returning the result of the final application. For example, array_foldr1(f, [a, b, c, d]) computes f(a, f(b, f(c, d))).
Returns an array consisting of all elements of array from start, inclusive, to start + length, exclusive. Out-of-range indices are dropped silently, so the resulting array may be shorter than length.
Returns the index of the first element of array which compares equal to item, or -1 if no element compares equal. The first element has index 0.
Returns 1 if item is an element of array; 0 otherwise.
Combine pairwise elements of array1 and array2 into a single array of pairs. For example, zip([a, b, c], [x, y, z]) produces [Pair(a, x), Pair(b, y), Pair(c, z)]. If the two arrays are not the same length, the resulting array is as long as the shorter array, with the remaining elements of the longer array discarded.
Separate an array of pairs into a pair of arrays with corresponding elements of array. The first output array contains the fst of each element of array, and the second output array contains the snd of each element. For example, unzip([Pair(a, x), Pair(b, y), Pair(c, z)]) produces Pair([a, b, c], [x, y, z]).
Just(value :: a)
Nothing
A container for a single value, which may or may not exist. As Mars has no “null” value, any value which might be non-existant should have type Maybe(a), and non-existant values should be represented as Nothing.
Represents the “end of file” condition in the output of the built-in function get_char. Note that eof is not actually a character; it is a special value indicating that no more bytes can be read from a file.
Writes string to standard output, where string is a list of byte integers. This calls put_char on each element of string. It is an error if any element is outside the range [0, 255]. Does not print a newline. See also: print_string.
Writes string to standard output. This calls put_char on each element of string. It is an error if any element is outside the range [0, 255]. Does not print a newline.
Writes a string representation of value to standard output. This is equivalent to print_string(show(value)). See also: print_string, show.