I'm trying to remove an element from an Array a using the index of the element but I can't find a way to do it with Lenses. I'm also wondering why Array does not provide an instance for the At lens. Any pointer on it?
1 Answer
I'm also wondering why Array does not provide an instance for the
Atlens.
You can look at the Control.Lens.At module docs for a hint:
... not Array-like ones, where you cannot satisfy the Lens laws
One of the laws which breaks is set l v' (set l v s) ≡ set l v' s. The reason being that deleting an index moves the other indices. So the following can't make sense:
myArray
& at 6 .~ Nothing
& at 6 .~ Just 10
I don't know of a way to have deleting array elements be Lens like.