How can I create an array of length n, all zeroes, except for some index i being equal to 1.0?
For example, if my magic function is foo it would work as follows:
foo:: Int -> Int -> [Double]
> foo 3 0
[1.0, 0.0, 0.0]
> foo 2 1
[0.0, 1.0]
> foo 1 1
** Exception: index greater than length!
Having a brain freeze…any help appreciated.
Note that that’s a list, not an array. Lists have O(i) indexing, arrays O(1), so one shouldn’t confuse the names of the datatypes.