You cannot do this using automatically created lenses for T If you want to stretch a little, you can first define
data T' abc = T' { _foo' :: c, _bar' :: a -> b} tt :: Iso (T ab) (T a' b') (T' aba) (T' a' b' a') tt = dimap (\(T xg) -> T' xg) (fmap (\(T' xg) -> T xg))
Then you can (automatically) create type-changing lenses for T' and use tt to use them to change values โโof type T ab through an isomorphism.
For example, by slightly changing the arguments, you can write
eg :: b -> T a (b -> c) -> T (a, b) c eg b = over tt $ (foo' %~ (,b)) . (bar' %~ uncurry)
Another approach, which would probably be better if you don't need to fuss with T , is too much to define as newtype around T' :
newtype T ab = T { getT :: T' aba }
Then you can skip Iso and just put things together. Reordering the arguments in the same way
eg' :: b -> T a (b -> c) -> T (a, b) c eg' b = T . (foo' %~ (,b)) . (bar' %~ uncurry) . getT
dfeuer
source share