I'm writing an AST library for a simple "dynamically typed" language. I have written my syntax tree and parser. Now I'm working on manipulating the AST, and I am interested in using the lens package for that purpose.
Consider
data Obj = Obj !(Map Text Obj)
| Arr ![Obj]
I can write a lens to manipulate object fields pretty easily:
field t (Obj m) = m^.at t
field _ _ = Nothing
but I have no idea where to start for manipulating Arr elements. I'd like a lens along the lines of:
arrIx :: Int -> Obj -> Maybe Obj
arrIx i (Arr objs) = objs^.someLensHere i
where someLensHere i = undefined
I will change my Obj representation for expedience, but it would still be helpful to know how to index on lists using lens.