On Thu, 10 Dec, 2015 at 6:43 PM, Kim-Ee Yeoh <ky3@atamo.com> wrote:<br><blockquote type="cite"><div dir="ltr">The wrong way is to try to write:<br><br><div><div>neededLift :: (Monad m) => ((b -> b) -> a -> a) -> (m b -> m b) -> m a -> m a<br><br></div><div>which, as Daniel pointed out, is impossible.<br></div></div><br><div><div><div><div><div><div class="gmail_extra">So we start with the isomorphisms:<br><br>isoL :: (f -> a) -> (a -> f -> f) -> ((a -> a) -> (f -> f))<br>isoL g s m f = s (m (g f)) f<br>isoR :: (f -> a) -> ((a -> a) -> (f -> f)) -> (a -> f -> f)<br>isoR _ m a = m (const a)<br><br></div><div class="gmail_extra">It turns out we really only need isoL, but isoR is there for completeness.<br><br></div><div class="gmail_extra">Then we write:<br><br><div>liftALabel :: Applicative f => a :-> b -> f a :-> f b</div><div>liftALabel l0 = lens g1 m1  where<br>   g1 = fmap (get l0)<br>   s1 = liftA2 (set l0)<br>   m1 = isoL g1 s1<br></div><br></div><div class="gmail_extra">Naturally, monad has been effect-reduced to applicative to admit more legal programs.<br></div><div class="gmail_extra"><br clear="all"><div><div>-- Kim-Ee</div></div></div></div></div></div></div></div></div></blockquote><br><div>Thanks guys, I appreciate your help. You've given me a lot of food for thought here, Kim-Ee, and I'll spin off a new project to explore this in isolation.</div><div><br></div><div>Si</div>