Operations on arrays
Rolf-Thomas Happe
rthappe@mathematik.uni-freiburg.de
Fri, 5 Mar 1999 16:30:03 +0100 (MET)
> but that doesn't work. The next thing to try is
>
> push_border x xs = newArray (1+size xs) (\i -> if (i==0) x xs.[i-1])
>
> but _that_ doesn't work either because there is no function
>
> newArray :: Int (Int -> a) -> {a}
>
> and I can't think why not. The simplest I've been able to come up with
> is
>
> push_border x xs = {createArray (1+size xs) x &
> [i] = xs.[i-1} \\ i <- [1..size xs]}
>
> which is not pretty. I've even wondered about
>
> push_border x xs = {y \\ y <- [x:[z \\ z <-: xs]]}
>
> which at least I'm confident will be linear time.
I sometimes create and initialise arrays in this slightly opulent way:
push_border x xs
= {f i \\ i <- [0..size xs]}
where
f 0 = x
f i = xs.[i-1]
rthappe