_SystemArray.dcl 1.94 KB
Newer Older
1 2
definition module _SystemArray

3 4 5 6 7
/**
 * Operations on arrays.
 * This is an internal class used to overload operations on different types of
 * arrays. It should not be instantiated outside of this module.
 */
8
class Array .a e where
9 10 11 12 13
	/**
	 * Select an element from an array.
	 * This is the function underlying the {{`.[]`}} construct.
	 * Also see {{`uselect`}}.
	 */
14
	select				:: !.(a .e) !Int	-> .e
15 16 17 18 19 20

	/**
	 * Select an element from a unique array.
	 * This is the function underlying the {{`![]`}} construct.
	 * Also see {{`select`}}.
	 */
21
	uselect				:: !u:(a e) !Int	-> *(e, !u:(a e))
22 23 24 25 26

	/**
	 * The size of an array.
	 * Also see {{`usize`}}.
	 */
27
	size				:: !.(a .e)			-> Int
28 29 30 31 32

	/**
	 * The size of a unique array.
	 * Also see {{`size`}}.
	 */
33
	usize				:: !u:(a .e)		-> *(!Int, !u:(a .e))
34 35 36 37 38 39 40 41 42 43

	/**
	 * Update an element in a unique array.
	 * This is the function underlying the {{`&`}} construct.
	 * Also see {{`replace`}}.
	 * @param The array
	 * @param The index to update
	 * @param The new element
	 * @result The new array
	 */
44
	update				:: !*(a .e) !Int .e -> *(a .e)	
45 46 47 48 49 50 51

	/**
	 * Create a new array. Also see {{`_createArray`}}.
	 * @param The number of elements
	 * @param The elements
	 * @result The array
	 */
52
	createArray			:: !Int e			-> *(a e)
53 54 55 56 57 58

	/**
	 * Create an empty array of a certain size. Also see {{`createArray`}}.
	 * @param The number of elements
	 * @result The array
	 */
59
	_createArray		:: !Int				-> *(a .e)
60 61 62 63 64 65 66 67 68 69

	/**
	 * Replace an element in an array and return the previous value.
	 * Also see {{`update`}}.
	 * @param The array
	 * @param The index to update
	 * @param The new value
	 * @result The old value
	 * @result The new array
	 */
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
	replace				:: !*(a .e) !Int .e -> *(.e, !*(a .e))


instance Array {!} a

instance Array {#} Int
instance Array {#} Char
instance Array {#} Real
instance Array {#} Bool

instance Array {#} {#.a}
instance Array {#} {!.a}
instance Array {#} {.a}

instance Array {#} a

//instance Array {#} File

instance Array {} a