The problem is not to explicitly indicate the type. Every time you want to have a lens container or a bypass (the inside of the lens, the lens inside the list, the lens inside Maybe ), you need to use ReifiedLens .
See this question for an explanation:
Why do we need Control.Lens.Reified?
So your example should be written as follows:
import Control.Lens f :: [Int] -> [[Int]] fl = [ l & i .~ 1 | Traversal i <- [Traversal $ ix 0] , l ^? i == Just 0 ]
Note that here Traversal is a constructor of the ReifiedTraversal type.
And it works as follows:
ghci> f [0,0,0] [[1,0,0]]
source share