A recent question led me to wonder how to convert a
forall f . Functor f => [LensLike f s t a b]
into a
[ReifiedLens s t a b]
There's an easy way to do it really slowly, by indexing into the list with !!, but it's quite incredibly inefficient. It feels like there should be enough parametricity to pull a trick similar to the one used in reflection, but I can't seem to figure anything out. Is it possible to do this efficiently at all?
Functor f -> [LensLike f s t a b]to[Functor f -> LensLike f s t a b]. We need to pass in aFunctor fto pull out a list to begin with, and there isn't one around.Functor f -> [LensLike f s t a b]must choose the length of their result list without inspecting theFunctor fargument in a meaningful way. Then it's easy to get the rest of the way from there. (Of course this claim is clearly not true of functions of typeFunctor F -> [LensLike F s t a b]for some particularF.)Functordictionary.ALensinstead ofReifiedLens. I'm wondering if there's a similar trick that works generally...