
Hello, I'm trying to write a lens for a datatype which seems easy in the Twan van Laarhoven encoding but I cannot find it as easy in the profunctorial one data Q5 a b = Q51 a (Identity b) | Q52 [b] lq5Twan :: Applicative f => (b -> f b') -> Q5 a b -> f (Q5 a b') lq5Twan f (Q51 a bs) = Q51 a <$> traverse f bs lq5Twan f (Q52 bs) = Q52 <$> traverse f bs data BT tt tt' b t t' a = BT1 (tt -> b) (t a) | BT2 (tt' -> b) (t' a) deriving (Functor,Foldable,Traversable) runBT (BT1 f x) = f x runBT (BT2 f x) = f x lq5Profunctor :: forall p a b b' . Traversing p => p b b' -> p (Q5 a b) (Q5 a b') lq5Profunctor = dimap pre post . second' . traverse' where pre (Q51 a x) = ((), BT1 (Q51 a) x) pre (Q52 bs) = ((), BT2 Q52 bs) post ((),x) = runBT x The issue here is that I need to project type 'b' into 2 different Traversable (sketched [] and Identity) so the traverse' must handle both together. Is the lq5Twan correct ? Which simpler ways to write the lq5Profunctor we have ? Thanks for help. paolino