definition module UtilArray

import StdArray, StdEnum, _SystemArray


//copyA a	:==	{ e \\ e <-: a }
// RWS FIXME overloading error filterA :: (e -> Bool) (a e) -> a e | Array a e;

// foldrA :: (a -> .(.b -> .b)) .b .(m a) -> .b | Array m a
foldrA op r a
	:==	foldrA r (size a - 1)
	where
		arrraySize
			=	size a
		foldrA r i
			| i == (-1)
				=	r
			// otherwise
				=	op a.[i] (foldrA r (i-1))

// foldlA :: (a -> .(.b -> .b)) .b .(m a) -> .b | ArrayElem a & Array .m
foldlA op r a
	:==	foldlA r 0
	where
		arrraySize
			=	size a
		foldlA r i
			| i == arrraySize
				=	r
			// otherwise
				=	op a.[i] (foldlA r (i+1))
