_SystemArray.dcl 3.74 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
	replace				:: !*(a .e) !Int .e -> *(.e, !*(a .e))

72 73 74 75 76
instance Array {!} a where
	uselect :: !u:{! e} !Int -> *(!e, !u:{! e})
	update :: !*{! .e} !Int !.e -> *{! .e}
	createArray :: !Int !e -> *{! e}
	replace :: !*{! .e} !Int !.e -> *(!.e, !*{! .e})
77

78 79 80 81 82
instance Array {#} Int where
	uselect :: !u:{# Int} !Int -> *(!Int, !u:{# Int})
	update :: !*{# e:Int} !Int !e:Int -> *{# e:Int}
	createArray :: !Int !Int -> *{# Int}
	replace :: !*{# e:Int} !Int !e:Int -> *(!e:Int, !*{# e:Int})
83

84 85 86 87 88
instance Array {#} Char where
	uselect :: !u:{# Char} !Int -> *(!Char, !u:{# Char})
	update :: !*{# e:Char} !Int !e:Char -> *{# e:Char}
	createArray :: !Int !Char -> *{# Char}
	replace :: !*{# e:Char} !Int !e:Char -> *(!e:Char, !*{# e:Char})
89

90 91 92 93 94
instance Array {#} Real where
	uselect :: !u:{# Real} !Int -> *(!Real, !u:{# Real})
	update :: !*{# e:Real} !Int !e:Real -> *{# e:Real}
	createArray :: !Int !Real -> *{# Real}
	replace :: !*{# e:Real} !Int !e:Real -> *(!e:Real, !*{# e:Real})
95

96 97 98 99 100
instance Array {#} Bool where
	uselect :: !u:{# Bool} !Int -> *(!Bool, !u:{# Bool})
	update :: !*{# e:Bool} !Int !e:Bool -> *{# e:Bool}
	createArray :: !Int !Bool -> *{# Bool}
	replace :: !*{# e:Bool} !Int !e:Bool -> *(!e:Bool, !*{# e:Bool})
101

102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
instance Array {#} {#.a} where
	uselect :: !u:{#{#.a}} !Int -> *(!{#.a},!u:{#{#.a}})
	update :: !*{#u:{#.a}} !Int !u:{#.a} -> *{#u:{#.a}}
	createArray :: !Int !{#.a} -> *{# {#.a}}
	replace :: !*{#u:{#.a}} !Int !u:{#.a} -> *(!u:{#.a},!*{#u:{#.a}})

instance Array {#} {!.a} where
	uselect :: !u:{#{!.a}} !Int -> *(!{!.a},!u:{#{!.a}})
	update :: !*{#u:{!.a}} !Int !u:{!.a} -> *{#u:{!.a}}
	createArray :: !Int !{!.a} -> *{# {!.a}}
	replace :: !*{#u:{!.a}} !Int !u:{!.a} -> *(!u:{!.a},!*{#u:{!.a}})

instance Array {#} {.a} where
	uselect :: !u:{#{.a}} !Int -> *(!{.a},!u:{#{.a}})
	update :: !*{#u:{.a}} !Int !u:{.a} -> *{#u:{.a}}
	createArray :: !Int !{.a} -> *{# {.a}}
	replace :: !*{#u:{.a}} !Int !u:{.a} -> *(!u:{.a},!*{#u:{.a}})

instance Array {#} a where
	uselect :: !u:{# e} !Int -> *(!e, !u:{# e})
	update :: !*{# .e} !Int !.e -> *{# .e}
	createArray :: !Int !e -> *{# e}
	replace :: !*{# .e} !Int !.e -> *(!.e, !*{# .e})
125 126

instance Array {} a