I am writing an AST library for a simple “dynamically typed” language. I wrote my syntax tree and parser. Now I am working on the management of AST, and I am interested in using the lens package for this purpose.
Consider
data Obj = Obj !(Map Text Obj) | Arr ![Obj]
I can write a lens to easily manipulate objects:
field t (Obj m) = m^.at t field _ _ = Nothing
but I don’t know where to start manipulating Arr elements. I need 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 view of Obj for convenience, but it would be useful to know how to index lists using a lens.
nomen source share