Mars requires the use of the io keyword to create a function capable of performing I/O operations. Due to the simplistic I/O annotation system in Mars, it is not possible to generalise higher-order functions to work on both pure and I/O function values. This is limiting: for example, the higher-order function map only operates on pure functions. Indeed, it would not be valid for map to operate on I/O functions, because map itself is not permitted to perform side-effects. However, this makes it impossible to easily apply an I/O action to each element of a list from within an I/O context.
This module provides an equivalent of every higher-order function in the prelude, but the versions here accept and return I/O-annotated functions. Where necessary, the versions here are themselves required to be called from an I/O context. In general, functions that manipulate (but do not call) I/O function values, such as flipio, may be called from a pure context, but functions that call I/O function values, such as mapio, must be called from an I/O context.
This module also provides the toio (read as “to I/O”) family of functions, which convert pure functions to I/O functions, in order to use pure functions with the other higher-order functions in this module.
Converts a pure nullary function f to an I/O function.
Converts a pure unary function f to an I/O function.
Converts a pure binary function f to an I/O function.
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.
Applies function to each item in list, in order from head to tail, producing a new list containing each of the results.
Applies function to each item in list, in order from head to tail, producing a new list containing only the items in list for which function returned a nonzero result.
Applies function to each item in array, in order from first to last, producing a new array containing each of the results.
Applies function to each item in array, in order from first to last, producing a new array containing only the items in array for which function returned a nonzero result.